简体   繁体   中英

Entity Framework and SQL Server datetime

I'm using EF with SQL Server and when I'm fetching a DateTime field that is DateTime on the MSSQL and on EF, I would get something like this:

"UpdateTime":"\/Date(1358716865533+0200)\/"

I have no idea what format is this (only that it shows some time with GMT+2 offset).

Any suggestions?

Second, I've tried to use ToString("") on that fields inside the LINQ that fetches the records and got an error that SQL doesn't support formatting this way - so I have no easy way to format that date as I want. Is there any way to apply formatting?

Thanks!

As said in the comment, this is a Unix format. You'll get a similar string when you serialize a DateTime with JavaScriptSerializer (JSON).

As for your second question. Yes it can be a nuisance that EF does not allow ToString in linq queries. On the other hand, EF is for data access, formatting is for UI. So you better do the formatting after you've fetched data from the database into memory display them somewhere.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM