2

I have a column create_date store in datetime.

When I query by this column, entity framework generate SQL like:

([Extent1].[create_date] >= CAST( @p__linq__3 AS datetime2)) AND ([Extent1].[create_date] <= CAST( @p__linq__4 AS datetime2))

The CAST here is not necessary, and it takes lower performance.

I have tried these:

[Column(TypeName = "datetime")]
public Nullable<System.DateTime> create_date { get; set; }

and

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity<myClass>().Property(o => o.create_date).HasColumnType("datetime");
}

Both don't work.

How to avoid CAST? I want entity framework generate SQL like:

([Extent1].[create_date] >= CAST( @p__linq__3 AS datetime)) AND ([Extent1].[create_date] <= CAST( @p__linq__4 AS datetime))

I don't think change .edmx: <Schema .. ProviderManifestToken="2008" is a good solution.

Yourway
  • 21
  • 6

0 Answers0