Adding Entities

Adding entities against an entity data model requires you to pass the instance of the entity to the Add method exposed by the entity set. For example, in our demonstration scenario we have a Products entity set exposing an Add method. The following code shows how you can programmatically create a new product and add it to the object model:

image

First, the code checks if the product already exists based on the specified condition. This is accomplished invoking the Single extension method, whose support is new in .NET Framework 4.0. It is something that you already saw in LINQ to SQL and not discussed thoroughly here. Notice how you simply ...

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.