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