Inserting Entities

You instantiate a new entity as any other .NET class and then set its properties. The following code shows how you can add a new Product to the Products entity set. Notice how the method receives the belonging category as an argument, which is required for setting the one-to-many relationship:

image

You simply set property values as you would in any other .NET class. Here you have to pay attention to add a non-null value to non-nullable members. In the previous example, QuantityPerUnit is a non-nullable and therefore must be assigned with a valid string. You can then omit assigning nullable members. LINQ to SQL can provide auto-increment ...

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.