Skip to content

Instantly share code, notes, and snippets.

View netdragoon's full-sized avatar

NetDragoon netdragoon

  • NetDragon
  • Brazil
View GitHub Profile
@netdragoon
netdragoon / TraducaoSql.sql
Last active November 9, 2017 00:17
TraducaoSql.sql
SELECT [x].[Id],
[x].[End],
[x].[Start]
FROM [Dates] AS [x]
WHERE [dbo].DATEDIFFDAY([x].[Start], [x].[End]) > 2
///////////////////////////////////////////////////////////////////////////
SELECT [x].[Id],
[x].[Start],
@netdragoon
netdragoon / DateDiffDaySelect.sql
Last active November 9, 2017 00:17
DateDiffDaySelect.sql
var date2 = db.Date
.Select(x => new
{
x.Id,
x.Start,
x.End,
Diff = Database.DateDiffDay(x.Start, x.End)
})
.ToList();
@netdragoon
netdragoon / ConsultaDateDiffDay.cs
Created November 8, 2017 23:57
ConsultaDateDiffDay.cs
var date1 = db.Date
.Where(x => Database.DateDiffDay(x.Start, x.End) > 2)
.ToList();
@netdragoon
netdragoon / DbFunctions.cs
Last active November 9, 2017 00:18
DbFunctions.cs
[DbFunction(FunctionName = "DATEDIFFDAY", Schema = "dbo")]
public static long DateDiffDay(DateTime start, DateTime end)
{
return 0;
}
@netdragoon
netdragoon / DateDiffDay.sql
Created November 8, 2017 23:39
DateDiffDay.sql
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[DATEDIFFDAY]
(
@start DateTime, @end DateTime
)
RETURNS bigint
AS
@netdragoon
netdragoon / SqlOutputOwneType.cs
Created November 8, 2017 14:57
SqlOutputOwneType
exec sp_executesql N'SELECT TOP(1) [e].[Id], [e].[Name],
[e].[Id], [e].[AddressCity],
[e].[AddressName], [e].[AddressNumber], [e].[AddressUf]
FROM [People] AS [e]
WHERE [e].[Id] = @__get_Item_0',N'@__get_Item_0 int',@__get_Item_0=1
@netdragoon
netdragoon / PeopleLinqFind.cs
Created November 8, 2017 14:56
PeopleLinqFind.cs
People result = db.People.Find(1);
@netdragoon
netdragoon / PeopleAddressMap.cs
Created November 8, 2017 14:51
PeopleAddressMap.cs
public class PeopleMap : IEntityTypeConfiguration<People>
{
public void Configure(EntityTypeBuilder<People> builder)
{
builder.ToTable("People")
.OwnsOne(x => x.Address, x =>
{
x.Property(a => a.City)
.HasColumnName("AddressCity")
.IsRequired().HasMaxLength(50);
@netdragoon
netdragoon / PeopleAddress.cs
Created November 8, 2017 14:49
PeopleAddress.cs
public class People
{
public int Id { get; set; }
public string Name { get; set; }
public Address Address { get; set; }
}
public class Address
{
public string Name { get; set; }
@netdragoon
netdragoon / ProductAndDetailsSQL.cs
Created November 8, 2017 13:55
ProductAndDetailsSQL.cs
SELECT TOP(1) [x].[Id], [x].[Description], [x].[Id], [x].[Amount], [x].[Price]
FROM [Products] AS [x]
WHERE [x].[Id] = 1