Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's several things you need to do in your code. First, to be able to see the list of product inventory records, you need to select them as part of your GetProducts domain operation:</p> <pre><code>Public Function GetProducts() As IQueryable(Of ProductPM) Return From p As Product In Me.ObjectContext.Products.Include("ProductInventories") Select New ProductPM With {.ListPrice = p.ListPrice, .ModifiedDate = p.ModifiedDate, .Name = p.Name, .ProductID = p.ProductID, .ProductNumber = p.ProductNumber, .ProductInventory = From i In p.ProductInventories Select New ProductInventoryPM With { .Quantity = i.Quantity, .ProductID = p.ProductID } } End Function </code></pre> <p>That will get them showing in the second data grid.</p> <p>You'll also need to add a constructor to your ProductPM class that initialises the ProductInventory class:</p> <pre><code>Public Sub New() ProductInventory = New List(Of ProductInventoryPM) End Sub </code></pre> <p>The final issue is that the insert domain operations are being called in the wrong order. As far as I can tell, the best way to handle this is as follows:</p> <ol> <li><p>Create an empty Insert domain operation for the ProductInventoryPM object. No logic is required in it, but the method is required in order for the ProductInventoryPM object to be able to be added to the ProductPM's inventory collection.</p> <pre><code>Public Sub InsertProductInventory(ByVal ProductInventoryPM As ProductInventoryPM) End Sub </code></pre> <p>NOTE: If you want to be able to add new inventory records after you've created the product + initial inventory record, then you will need to add logic to this domain operation after all.</p></li> <li><p>Insert the inventory objects in the ProductPM's Insert domain operation. An advantage of this is that there's no need to call SaveChanges.</p> <pre><code>Public Sub InsertProduct(ByVal ProductPM As ProductPM) Dim Product As New Product Product.Name = ProductPM.Name Product.ProductNumber = ProductPM.ProductNumber Product.ListPrice = ProductPM.ListPrice Product.SellStartDate = DateTime.Now Product.ModifiedDate = DateTime.Now Product.SafetyStockLevel = 1000 Product.ReorderPoint = 700 Product.StandardCost = 0 Product.DaysToManufacture = 3 Product.rowguid = Guid.NewGuid() Me.ObjectContext.Products.AddObject(Product) Me.ChangeSet.Associate(ProductPM, Product, AddressOf UpdateProductPMKey) For Each ProductInventoryPM As ProductInventoryPM In ProductPM.ProductInventory Dim productInventory As New ProductInventory With productInventory .Bin = 1 .LocationID = 1 .ModifiedDate = DateTime.Now .ProductID = ProductInventoryPM.ProductID .Quantity = ProductInventoryPM.Quantity .Shelf = "A" End With Product.ProductInventories.Add(productInventory) Me.ChangeSet.Associate(ProductInventoryPM, productInventory, AddressOf UpdateProductInventoryKey) Next End Sub </code></pre></li> </ol> <p>Now if you run it, everything should work OK. Let me know how it goes.</p> <p>Chris</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload