Fields on related fields

Posts   
 
    
brent
User
Posts: 8
Joined: 15-Jul-2006
# Posted on: 21-Jul-2006 22:47:40   

LLBLGen 2, Sql2000, ASP.NET 2

I'm sorry if this question has been asked a lot but I can't find it. Lets say I have two tables; Order and Customer, which are related on Order.CustomerId to Customer.CustomerId. I want to make an insert into these tables in one call like such:


OrderEntity o = new OrderEntity();
o.Fname = "someones"; // Customer
o.Lname = "name"; // Customer
o.Qty = 2; // Order
o.Save();

I was thinking that by mapping all the Customer fields onto Order in the Orders FieldsOnRelatedFields in the LLBL designer that this would work. However I haven't been successful yet. Does this in fact work and I'm doing it wrong, or is there some different way to do this type of thing?

I've played with it a few ways and I either get this error:

Cannot insert the value NULL into column 'CustomerId'

Or it says the column Fname is null and can't be inserted.

thanks for any help and direction! Brent

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 22-Jul-2006 03:28:25   

Fields on related fields are read-only by default if you don't change the FieldsOnRelatedFieldAreReadOnly user preference. Try changing this value in the designer and see if you can then save values to both entities.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 22-Jul-2006 09:52:13   

Your code also won't work, you've to first set the related customer property to a new instance of Customer, then set the fields.

Frans Bouma | Lead developer LLBLGen Pro
brent
User
Posts: 8
Joined: 15-Jul-2006
# Posted on: 23-Jul-2006 06:51:49   

Yup, I was missing the new instance of Customer. Thanks! smile smile

brent
User
Posts: 8
Joined: 15-Jul-2006
# Posted on: 23-Jul-2006 07:23:12   

How do I accomplish this using the LLBLGenProDataSource? In this instance I'm using a DetailsView with the LLBLGenProDataSource for inserts. Do I need to manually handle the performWork event to add the new Customer instance, or is there a 'no code' way to do this (like through InsertParameters or something)?

Thanks again!

sparmar2000 avatar
Posts: 341
Joined: 30-Nov-2003
# Posted on: 23-Jul-2006 17:19:30   

Hello brent

This can be done by overriding the new OnInitialized method in v2.0 entities, in partial class. Please search for 'Partial class' in the manual for details. In there, create a new CustomerEntity.

You can also bind to the events in the entity collection - bit tricky, as normally you won't use fields mapped onto related fields this way but possible.

brent
User
Posts: 8
Joined: 15-Jul-2006
# Posted on: 25-Jul-2006 05:28:14   

I overrided onInitialzed, worked like a charm simple_smile

thanks