Two Tables = 1 Entity ?

Posts   
 
    
ianvink
User
Posts: 393
Joined: 15-Dec-2006
# Posted on: 02-Nov-2007 17:48:22   

We have a need to create a single CustomerEntity, but have the source data come from 2 Customer tables. I have a CustomerA table, but it has an extension table CustomerB. Not a great design, but it's in the legacy system so we have to deal with it.

So basically much like a TypedList, but with the richness and updateability of an Entity.

If this is not possible, would it be possible to create a CustomerEntityA and a CustomerEntityB and then 'partial class out' a single Customer?

One idea would be to base the Customer domain model on CustomerA, then create partial class Fields in CustomerA which talks to CustomerB. (Anyone remember what the name of the pattern is for this?)

Ideas?

Anonymous
User
Posts: 0
Joined: 11-Nov-2006
# Posted on: 02-Nov-2007 18:25:51   

I remember asking something similar on version 2.0 and the answer was no. Unless something has changed in version 2.5 i think your best bet is to create a composite class that wraps the two entities and manages interaction with the underlying data.

Would be interested to hear other view on the subject. What would others do?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 03-Nov-2007 06:14:05   

Some options/hints:

  1. Add _entityA _properties that indeed map to _entityB _fields using "Fields on related fields" (Designer) or by code (userCodeRegion or partial classes). So Customer.CustomerCity indeed maps to Customer.CustomerAddress.City.

  2. Using Inheritance. I assume there is a main entity (PK side). So you could make the entityB inherits from entityA, then you will see entiityB at code as the total of fields of entityA and entityB. So you could rename enityB to become "TheWholeCustomerEntity".

David Elizondo | LLBLGen Support Team
ianvink
User
Posts: 393
Joined: 15-Dec-2006
# Posted on: 03-Nov-2007 11:21:02   

Great!

Can you give me the steps/location in manual to do option 2, I couldn't figure that out.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 04-Nov-2007 20:38:25   

Hope helpful wink

David Elizondo | LLBLGen Support Team
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 05-Nov-2007 12:23:25   

also an option is (if both tables have a 1-to-1 relation) is to create a view that contains all fields from both tables and then create an entity based on this view.