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:

Sub AddProduct(ByVal categoryReference As Category)    Try        Dim check = northwindContext.Products.                    Single(Function(p) p.                    ProductName = "Italian spaghetti")    Catch ex As InvalidOperationException        Try            Dim prod As New Product            With prod                .ProductName = "Italian spaghetti"                .QuantityPerUnit ...

Get Visual Basic 2015 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.