I am fairly competent with LLBLgen Pro now, however I don't seem to understand some of the basics. I repeatedly run into problems where graphs (objects fetched using prefetch paths with several associated collections) are inserting additional rows into the child collections when I try to persist. It is a large app and hard to isolate sample code to demonstrate. I just thought there might be some general guidelines around this issue, or maybe some threads where this topic has been discussed already...?
I just did a little more testing.
I had an object called Product.
Product has a 1-many with Formulation.
When I created a NEW Product I could do this (pseudo-code) (new Product entity):
formulation = GetOneFromDb(fid);
product = new ProductEntity();
product.Formulation = formulation;
adapter.SaveEntity(product);
This works fine so far.
However when I do the following (use an existing product fetched from db):
formulation = GetOneFromDb(fid);
product = GetOneFromDb(pid);
product.Formulation = formulation;
adapter.SaveEntity(product);
I end up with a duplicate of the formulation record in the Formulation table.
Finally if I do this (use the int PK value directly):
formulation = GetOneFromDb(fid);
product = GetOneFromDb(pid);
product.Formulation = null;
product.FormulationId = formulation.Id;
adapter.SaveEntity(product);
Everything works fine now.
Can someone PLEASE explain the rules about when to assign objects to properties such as:
product.Formulation = formulation;
versus setting the Id directly:
product.FormulationId = formulation.Id;
This is very confusing to me. I apologize if I missed a thread or missed it in help file...
Steve