Linq To Sql: handle NewID ()

Hey, I'm trying to add data to my sqlserver using Linq To Sql, in the table, the data design is to get NEWID () when inserting a new row, but linq to sql ignore it and the cell is in null.

thank!

+3
source share
1 answer

It looks like you expect the guid value to be automatically generated for you right at the time of input. It looks like this column has DEFAULTof NewID().

LINQ To SQL table, . , , . , INSERT .

alt text

:

Customer c = new Customer{FirstName="foo"};
db.Customers.InsertOnSubmit(c);
db.SubmitChanges();
string someGuid = c.MyGuidField.ToString();
+9

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


All Articles