Save related entity (or not)

Posts   
 
    
Gabbo
User
Posts: 56
Joined: 12-Jun-2006
# Posted on: 25-Apr-2007 00:09:31   

I'm using version 2, adapter, ASP.NET 2.0, targeting SQL Server 2000

I have a line item related to a product. I want to assign the product to the item.Product property and have it either create a new product (if I've created a new product object), or just refer to the product identifier (if I've fetched an existing product) when the parent LineItem is saved. Is this possible?

I'm using the following adapter over-ride:

order.Product = product; // this is either a newly created product or a fetched product adapter.SaveEntity( order, false, true);

It creates the new products just fine, but if I've found an existing product (using adapter.FetchEntity( product ), after assigning the primary key), it still tries to create a new product.

Thanks in advance!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Apr-2007 09:43:00   

but if I've found an existing product (using adapter.FetchEntity( product ), after assigning the primary key), it still tries to create a new product.

Would you please post a code snippet for the above case?

Gabbo
User
Posts: 56
Joined: 12-Jun-2006
# Posted on: 25-Apr-2007 15:59:55   

Walaa wrote:

but if I've found an existing product (using adapter.FetchEntity( product ), after assigning the primary key), it still tries to create a new product.

Would you please post a code snippet for the above case?

I'll assume this means that I'm not experiencing the expected behavior. I'll look into this further on my side and if I still continue to have problems, I'll post further code. This is just a quick prototype to proof a data model, so I haven't spent much debugging time.

Thanks!

Gabbo
User
Posts: 56
Joined: 12-Jun-2006
# Posted on: 25-Apr-2007 17:05:56   

Gabbo wrote:

Walaa wrote:

but if I've found an existing product (using adapter.FetchEntity( product ), after assigning the primary key), it still tries to create a new product.

Would you please post a code snippet for the above case?

I'll assume this means that I'm not experiencing the expected behavior. I'll look into this further on my side and if I still continue to have problems, I'll post further code. This is just a quick prototype to proof a data model, so I haven't spent much debugging time.

Thanks!

Hi again. Thanks for putting up with the newbie question. This is working properly; it was my problem.

I'm processing line items, and just needed to create the product with refetch when one didn't exist. I was originally allowing the parent order object to create the new product(s) for each of the line items. The problem is that with multiple line items that might contain the same product that doesn't yet exist, the product objects are correctly (in LLBLGen terms) marked as new. This is fine for the first new one, but fails for the second.

By the way, if you look at all my posts I seem to gripe and complain quite a bit about the product, but I always use LLBLGen as an example of how a software company should be run. Just as most of the other developers that use your product, we also use quite a few other products, and this BY FAR has the best support and product maturity.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Apr-2007 17:57:02   

Thank you very much for the positive feedback, and you are welcomed at any time.