0
我有几个字段的表,其中之一是Id自动增量/主字段。使用Linq to SQL插入新记录后,是否可以读取新记录Id字段值?Linq到SQL和SQL Server自动增加字段
我有几个字段的表,其中之一是Id自动增量/主字段。使用Linq to SQL插入新记录后,是否可以读取新记录Id字段值?Linq到SQL和SQL Server自动增加字段
是的,当您拨打SubmitChanges
时,Id属性会自动设置。例如:
var customer = new Customer();
Console.WriteLine(customer.Id); // 0
context.Customers.InsertOnSubmit(customer); // Attach it to the context
context.SubmitChanges();
Console.WriteLine(customer.Id); // 1