SQL Server supports the auto-generation of primary key
values through the identity setting. When creating a new LINQ business object,
the value of the primary key is zero; meaning no value has been assigned. Calling
SubmitChanges on the DataContext refreshes this value with the auto-generated
value assigned from the backend database. Let us take a look at an example.
When creating a new business object, the value of the
primary key is illustrated below.
Listing 6
Product product = new Product();
product.Name = "Value";
//Assign remaining values.
Listing 7
Assert.AreEqual(0, product.ProductKey);
But after the call to submit changes, the value is updated
to:
_context.SubmitChanges();
Assert.AreEqual(6, product.ProductKey);
The product key is assigned to an actual value after the
product is refreshed.