C # + linq - Insert DateTime value in Db in desired format

I have a Db server with DateTime fields in the format "yyyy-MM-dd mm: hh: ss"
I am trying to use linq2sql to insert a DateTime member into a DateTime field in one of my tables.
When I do this in SQL, I convert the DateTime as follows:
"Paste to ... Convert (datetime, getdate (), 120) ..." But when I try to send an object from Linq, the date time inserts the wrong format.

Is there a way to determine the format that will be inserted into Db in Linq? Or is it a DateTime Issue object?

0
source share
1 answer

You do not have to deal with the string format when you pass dates and times to the database, more than if you were passing a number. The database should handle all this for you without any conversion. This is true, whether you use LINQ or inside SQL - almost at any time when you have to manually perform string conversions between types at the database level, you should look for a better solution.

If you read the value returned from the database (like DateTime again), does it have the correct value? If not, how is this wrong?

+5
source

Source: https://habr.com/ru/post/1303593/


All Articles