Working with Relations

Posts   
 
    
gj1118
User
Posts: 30
Joined: 21-Jul-2010
# Posted on: 21-Aug-2010 01:30:51   

Hi,

I am using LLBLGEN 3.0

Let me first tell you, its an awesome product. I am recommending it to everybody these days simple_smile

I had a doubt , though and I was wondering, if anybody could help me please with it.

I have attached a snapshot of the related tables for your reference along with this post.

As you can, see from the database diagram , I have a three relations between , two same tables, i.e. between Clients and Address. but from three different columns

Why I did that ? A client can have three addresses, A client Address, a Shipping Address and a Billing Address. This is why , I created three relations from clients table to the Addresses table.

I did not want to use the Intermediate table because, creating the intermediate tables would not help me to map the Main Address, Billing Address and the Shipping Address of the client properly.

I think there is some problem with my relations. If there is not , could you please help me how to work with the generated code. I know I can use Address, Address_ and Address__ but how to use it, is what fails me

Please see the database diagram attached with this post for some help understanding

THanks for taking time out to help me !

With Regards Gagan

Attachments
Filename File size Added on Approval
Client_Address.JPG 26,735 21-Aug-2010 01:31.15 Approved
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 21-Aug-2010 08:18:25   

Hi Gagan,

Your relations are perfectly normal. In the LLBLGen Designer you can change the Navigators name for each one. So instead of Address, Address, Address_ you would get CustomerAddress, ShippingAddress, BillingAddress. The rest is the same as if you just have one relation. So prefetchpaths, relations, navigators, etc, at code is the same.

David Elizondo | LLBLGen Support Team
gj1118
User
Posts: 30
Joined: 21-Jul-2010
# Posted on: 21-Aug-2010 08:48:59   

@Daelmo

Thanks for taking time out to respond to my query. Thanks , also for checking the relations between my tables.

would this be a correct way of doing this



Address address = new Address();
address.StreetAddress = "Some Street Address Here";
address.Save();

Client.ClientAddress= address.AddressId;


I also understand , that i need to replicate the above code for shipping address as well as billing address of the client

so for the client's shipping address the above code would be like



Address_  shippingaddress = new Address_(); 
shippingaddress .StreetAddress = "Some Street Address Here";
shippingaddress .Save();

Client.ClientShippingAddress= shippingaddress .AddressId;


and so and so forth for the Billing Address

If the above code is valid, cant i deepsave it , using the client entity ?

Thanks again..

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-Aug-2010 22:12:28   

gj1118 wrote:

would this be a correct way of doing this



Address address = new Address();
address.StreetAddress = "Some Street Address Here";
address.Save();

Client.ClientAddress = address.AddressId;


Not exactly. Remember that Client.ClientAddress is a property of type AddressEntity and address.AddressId is int, you you can't assign and int to an AddressEntity. You can do:

Client.ClientAddress = address;

or

Client.ClientAddressId = address.AddressId;

gj1118 wrote:

I also understand , that i need to replicate the above code for shipping address as well as billing address of the client

so for the client's shipping address the above code would be like



Address_  shippingaddress = new Address_(); 
shippingaddress .StreetAddress = "Some Street Address Here";
shippingaddress .Save();

Client.ClientShippingAddress= shippingaddress .AddressId;


and so and so forth for the Billing Address

If the above code is valid, cant i deepsave it , using the client entity ?

You can deep-save it from client for instance.

client.ClientAddress = someNewAddress;
client.BillingAddress = someNewBillingAddress;
cilent.ShippingAddress = someNewShippingAddress;

// save recursively
client.Save(true);
David Elizondo | LLBLGen Support Team