Using DateTime in Dynamic LINQ to Entities

前端 未结 4 1035
醉梦人生
醉梦人生 2021-01-05 09:34

I am using LINQ to Entities to retrieve item purchase dates as follows:

where EntityFunctions.TruncateTime(order.PurchaseDate) == myPurchaseDate.date
         


        
4条回答
  •  既然无缘
    2021-01-05 09:50

    If your queries will often search by just the date aspect, another approach to consider, if available with your SQL Server database, would be to redundantly store a truncated version of the datetime column, in a date column type. See http://msdn.microsoft.com/en-us/library/bb630352.aspx).

    All of your queries can then perform better because there are no conversions necessary, are less prone to developer error. And they're easier to query in plain old SQL as well.

    Your EF queries would then query on the SQL Server date column

提交回复
热议问题