here is my code.
List<NPSEntity> Data = null; ;
using (var db = new NPSDbContext())
{
Data = (from n in db.NPSDatas
orderby n.AddDate, n.CountryCode
where DbFunctions.TruncateTime(n.NPSDate) >= StartDate.Date && DbFunctions.TruncateTime(n.NPSDate) <= EndDate
select n).ToList();
}
NPSData = Data.Select(n => new NPSEntity
{
NPSDate = DbFunctions.TruncateTime(n.NPSDate),
NPSAmount = n.NPSAmount,
AddDate = n.AddDate,
ModDate = n.ModDate,
UserID = n.UserID,
CountryCode = n.CountryCode
}).ToList();
if (NPSData!=null)
{
CountryCodes = NPSData.Select(e => e.CountryCode).Distinct();
CountryCount = CountryCodes.Count();
}
this line throwing error NPSDate = DbFunctions.TruncateTime(n.NPSDate),
This function can only be invoked from LINQ to Entities
my objective is to remove time portion from NPSDate NPSDate = DbFunctions.TruncateTime(n.NPSDate)
that is why i used DbFunctions.TruncateTime
function.
tell me how could i fix this problem or tell me how could i remove time portion from NPSDate when fetching data from db. my NPSDate property look like public DateTime? NPSDate { get; set; }
that is why i can not use NPSDate.Date
please guide me. thanks