Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi ,
please help me
i want to Compare my EndDate with PresentDate in linq query, here problem is
EndDate is stored as String type in my sql database. Datetime.parse is not working in lenq query. i tried with Datetime.parse
and DateTime.ParseExact

i got an error everttime

LINQ to Entities does not recognize the method 'System.DateTime ParseExact(System.String, System.String, System.IFormatProvider)' method, and this method cannot be translated into a store expression.
Posted
Updated 4-Oct-13 22:03pm
v2
Comments
Tejas Vaishnav 5-Oct-13 4:05am    
what you are trying so far? can you please share your linq query in which you are facing this issue.

I think try to use Convert.ToDateTime method, but also let your code block share and use improve question functionality to add your code.
dorababu407 5-Oct-13 4:39am    
hi Tejas Vaishnav,
thanks for rply, here is my code.
iam trying to get records only EndDate is greater than PresentDate using Linq Query in MVC4.

DateTime PresentDate = DateTime.Now.Date;
var EventDetails = (from e in _repository.EventInfo
where e.WasEventLive == true && e.EndDate < PresentDate
select new UserCommonPageModel
{
EventInfoId = e.EventInfoID,
EventTitle = e.EventTitle,
EventEndDate = e.EndDate
}).ToList();
return View(EventDetails);
dorababu407 7-Oct-13 13:05pm    
hi Tejas Vaishnav ,thanks for rply.
i got solution after refer this link
http://stackoverflow.com/questions/7740693/big-issue-in-converting-string-to-datetime-using-linq-to-entities.

Convert.ToDateTime does,t works. i just done Date comparision in foreach loop after getting data from database using link query.
here is my code
public ActionResult UserCommonPage()
{
DateTime PresentDate = DateTime.Now.Date;
DateTime EndDate;

IEnumerable<usercommonpagemodel> Data = (from e in _repository.EventInfo
where e.WasEventLive == true
select new UserCommonPageModel
{
EndDate = e.EndDate,
EventEndDate = e.EndDate,
EventInfoId = e.EventInfoID,
EventTitle = e.EventTitle,
VenueName = e.VenueName,
EventLogoURL = e.EventLogo,
EventDescription = e.EventDescription,
EventStartDate = e.StartDate,
}).ToList();

List<usercommonpagemodel> obj = new List<usercommonpagemodel>();
int Count = Data.Count();

foreach (var item in Data)
{
EndDate = Convert.ToDateTime(item.EndDate);
if (EndDate.Date >= PresentDate.Date)
{
obj.Add(item);
}
}


return View(obj);

}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900