Skip to main content

Posts

Showing posts with the label entity framework

Truncate/Ignore time part of DateTime column in Entity Framework

There are times when you want to perform query on only date part of the column that has type DateTime in database. Entity framework does not support DateTime.Date property but provides a helper class EntityFunctions . EntityFunctions has a method TruncateTime that can be called in Linq2Entities query and truncates the time part from datetime. Here is how to use it using (AccountEntities dal = new AccountEntities ()) {               DateTime dtStart=DateTime.Now.AddDays(-20).Date;               DateTime dtEnd=DateTime.Now.Date;     transactions = (from t in dal.Transactions                             where                             EntityFunctions.TruncateTime (t.TransactionDate.Value)                     ...