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:
Sub AddProduct(categoryReference As Category) Dim aProduct As New Product aProduct.ProductName = "Italian spaghetti" aProduct.Discontinued = False aProduct.QuantityPerUnit = "10" aProduct.UnitPrice = 0.4D 'Setting the relationship aProduct.Category = categoryReference 'Adding the new product to the object model northwind.Products.InsertOnSubmit(aProduct)End Sub
You set property ...
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.