Friday, 15 June 2012

c# - Get formatted date using entity frame work linq -


How do I get the formatted date in the unit collection, I am using the code given below

  Var objholiday = context.tblHolidayCalendars.Where (x => x.isDelete == incorrect). Select (x = & gt; new {x.recordId, x.date.ToString ("yyyy / MM / dd"),});  

This is not working. Any way to do this work

You can not easily format the date in a IQueryable query ...

  var objholiday = context.tblHolidayCalendar Where (x = & x; x.isDelete == incorrect). Select (x = & gt; New {x.recordId, x.date, // extract here}}  

Add

 . ASEnumerable (). Select (x = & gt; new {xrecordId, date = x.date.ToString ("yyyy / MM / dd"}};  

Because SQL Server doesn Tostring () method is not known.

Then you return a date (as DateTime ) and then at the local level ( .enememreble ( ) ) You need.

Note that if the date can be null then you have a copy:

  .anemmereble () select (x = & g T; New {x.recordId, date = x.date! = Null? X.date.Value.ToString ("yyyy / MM / dd"): Faucet};  

Note That you can do date format the SQL side, but it is a bit more complex. How to do this depends on the version of EF you are using, because you have some SQL Basic functions You should tell EF to use and you do not take much profit from doing this.


No comments:

Post a Comment