Aggregating attributes from parent and child entities

Posts   
 
    
mario.muja avatar
mario.muja
User
Posts: 37
Joined: 03-May-2005
# Posted on: 31-May-2005 08:26:50   

Hi, in our data model, we have a table Component (parent) and a detail table SpecialComponent (child).

We would like to get an object SpecialComponent from LLBLGen, which enables access to all attributes belonging to SpecialComponent AND all attributes belonging to Component.

Does LLBLGen support SpecialComponent to inherit all attributes from Component or do we have to define a typed list, which combines all attributes from these two tables in an SQL join manner?

In case we have to work with a typed list: are typed lists readonly or do they support updates, which are routed to the correct tables regardless of the fact from which table the attributes have been taken?

Thanks for your help.

Best Regards, Mario

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 31-May-2005 09:57:29   

Inheritance is currently in development, though if component and specialcomponent have a 1:1 relation, you can create Fields mapped on related fields in specialcomponent, which are mapped on fields in component. Witha prefetch path you can fetch them together. (or if you're using selfservicing, the component is then fetched using lazy loading). Saves have to be done recursively.

Frans Bouma | Lead developer LLBLGen Pro
mario.muja avatar
mario.muja
User
Posts: 37
Joined: 03-May-2005
# Posted on: 01-Jun-2005 08:38:48   
though if component and specialcomponent have a 1:1 relation

What if the relation type is 1:n?

, you can create Fields mapped on related fields in specialcomponent, which are mapped on fields in component. Witha  prefetch path you can fetch them together. 

Can you please show me some example code? Would I receive a specialcomponent object with all the attributes aggregated for the 1:1 relation?

(or if you're using selfservicing

We plan to use the adapter approach, because we have to serve more than one database product.

Saves have to be done recursively.

Is this done automatically or would I have to code the recursion manually?

Thanks for your help.

Regards, Mario

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 01-Jun-2005 09:47:38   

mario.muja wrote:

though if component and specialcomponent have a 1:1 relation

What if the relation type is 1:n?

Then you can create a field mapped on a related field in the entity with the opposite relation. So: Customer 1:n Order. Then in Order, you have a m:1 relation with Customer, and you can create a field mapped onto a field in Customer.

, you can create Fields mapped on related fields in specialcomponent, which are mapped on fields in component. Witha prefetch path you can fetch them together.

Can you please show me some example code? Would I receive a specialcomponent object with all the attributes aggregated for the 1:1 relation?

If 2 entities have a 1:1 relation, and you create a couple of fields mapped onto related fields in one of them (which thus map on fields in the related entity), you just have to fetch the two entities together, using a prefetch path. So instead of doing: adapter.FetchEntity(orderEntity); you specify a prefetch path which also fetches the customer:


IPrefetchPath2 path = new PrefetchPath2((int)EntityType.OrderEntity);
path.Add(OrderEntity.PrefetchPathCustomer);
adapter.FetchEntity(orderEntity, path);

(or if you're using selfservicing

We plan to use the adapter approach, because we have to serve more than one database product.

Saves have to be done recursively.

Is this done automatically or would I have to code the recursion manually?

Saves are recursive by default in Adapter. You can manually specify if you don't want that, by using an overload of SaveEntity()

Frans Bouma | Lead developer LLBLGen Pro
mario.muja avatar
mario.muja
User
Posts: 37
Joined: 03-May-2005
# Posted on: 01-Jun-2005 10:10:28   

Can you please also show an example that shows, how to access attributes of the entities order and customer used in your code example above?

Regards, Mario

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 01-Jun-2005 10:53:28   

mario.muja wrote:

Can you please also show an example that shows, how to access attributes of the entities order and customer used in your code example above?

Regards, Mario

customer.CompanyName order.CompanyName (field mapped onto order.Customer.CompanyName)) customer.Fields[(int)CustomerFieldIndex.CompanyName].CurrentValue customer.Fields["CompanyName"].CurrentValue

etc.

Frans Bouma | Lead developer LLBLGen Pro