I am getting an error "System.NotSupportedException: LINQ to Entities does not recognize the method 'System.DateTime Parse(System.String)' method and this method cannot be translated into a store expression." when trying to run below code in C# ASP.NET MVC
var LastWeekDay = DateTime.Now.AddDays(-7);
using (var context = new bwavenueEntities())
{
QuotesFeteched = context.QuoteTableMains.Where(a => Convert.ToDatetime(a.DateCreated) > LastWeekDay).Count();
}
I am using Entity framework in my asp.net MVC project, how can I resolve it? Any idea or help?
Thanks
Try using
var LastWeekDay = DateTime.Now.AddDays(-7);
using (var context = new bwavenueEntities())
{
QuotesFeteched = context.Where(a => DateTime.Parse(a.DateCreated) > LastWeekDay).ToList();
}
OR
it will be better if you convert your database columns of DateCreated into "datetime" type, instead of "string" type.
OR
TransRepository
.Entities.ToList()//forces execution
.Where(x =>Convert.ToDateTime(x.DateCreated) >= dtFrom)
But above method will fetch entire data and will consume lots of memory.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly