Confusion on entity use with selection lists

Posts   
 
    
IowaDave
User
Posts: 83
Joined: 02-Jun-2004
# Posted on: 25-Mar-2005 18:39:03   

I keep getting this question and I am not sure how to answer it. Working with 2 tables, for example: There is a foreign key relationship on colorcode.

Product ProductId ColorCode 1_________1 2_________1 3_________1

Colors ColorCode 1 2 3 I do a FetchEntity for Product 1 ProductEntity. The question asked is: "Can you also get the list of all available Colors (1,2, 3) in the ProductEntity?"

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 25-Mar-2005 19:02:33   

Yes, use a prefetch path for that simple_smile

Frans Bouma | Lead developer LLBLGen Pro
IowaDave
User
Posts: 83
Joined: 02-Jun-2004
# Posted on: 25-Mar-2005 22:32:52   

****Sorry for my total lack of understanding on this -

Here is the code I am running and I do get the Colors row for the color being used by the selected product simple_smile but I want **all the rows **from the colors table. I'm obviously missing a piece of code here, but I haven't seen an example of this in the doc.

ProductEntity pe = new ProductEntity(1); using (DataAccessAdapter da = new DataAccessAdapter()) {

            IPrefetchPath2 prefetchPath = new PrefetchPath2((int) 
                                       EntityType.ProductEntity);


             prefetchPath.Add(ProductEntity.PrefetchPathColors);

              da.FetchEntity(pe, prefetchPath);
            }
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 26-Mar-2005 11:09:57   

ooh! simple_smile I though you wanted just the related colors.

If you want all the colors, do this: ProductEntity pe = new ProductEntity(1); using (DataAccessAdapter da = new DataAccessAdapter()) { da.FetchEntity(pe); da.FetchEntityCollection(pe.Colors, null); }

Frans Bouma | Lead developer LLBLGen Pro
IowaDave
User
Posts: 83
Joined: 02-Jun-2004
# Posted on: 26-Mar-2005 20:25:22   

Thanks, I thought I could do it through one FetchEntity call, but that's ok.... however....

I think I see the problem here. Because product to colors is a 1 to 1 relationship, Colors is a ColorsEntity and not an EntityCollection so I can't do a FetchEntityCollection(pe.Colors).

This is a slight problem in that our client views are wanting the collections that support editing an entity. We are trying to build a very chunky access layer in that the data needed are all contained in the entity class. Couldn't you make Colors a collection and even if it's a one to one, then it would have just one element, but one could fill up the collection with, for example, all available selections. That would satisfy our desire to use the entity class to pass all the data back to the client. Cool, huh? or maybe not. I realize it makes sense for a 1:1 to be a single entity but I also think the collection class would be more versatile. Or am I trying to bend your creation to my warped way of doing things? sunglasses

What are your thoughts?

Thanks, Dave

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 28-Mar-2005 13:37:25   

IowaDave wrote:

Thanks, I thought I could do it through one FetchEntity call, but that's ok.... however....

I think I see the problem here. Because product to colors is a 1 to 1 relationship, Colors is a ColorsEntity and not an EntityCollection so I can't do a FetchEntityCollection(pe.Colors).

It's an m:1 relation wink That makes sense. If you have an FK from product to colors, there can be just 1 color associated with a product entity, so if you load a product entity, you get just 1 color entity as well, namely the one associated with the product entity.

This is a slight problem in that our client views are wanting the collections that support editing an entity. We are trying to build a very chunky access layer in that the data needed are all contained in the entity class. Couldn't you make Colors a collection and even if it's a one to one, then it would have just one element, but one could fill up the collection with, for example, all available selections. That would satisfy our desire to use the entity class to pass all the data back to the client. Cool, huh? or maybe not. I realize it makes sense for a 1:1 to be a single entity but I also think the collection class would be more versatile. Or am I trying to bend your creation to my warped way of doing things? sunglasses

hehe simple_smile Well, making it a collection would not be logical. What I think would make more sense, is that you create a separate object which contains the collections for the editor. This way, you just fetch one time the colors collection, even though you have 10 products loaded simple_smile

Frans Bouma | Lead developer LLBLGen Pro
IowaDave
User
Posts: 83
Joined: 02-Jun-2004
# Posted on: 28-Mar-2005 18:02:58   

Well, making it a collection would not be logical. What I think would make more sense, is that you create a separate object which contains the collections for the editor. This way, you just fetch one time the colors collection, even though you have 10 products loaded

I think there is a lack of understanding by our team of what data the entity should contain. As I stated at the beginning of the thread, they keep asking the same question. Thanks for helping me clear this up.

stuck_out_tongue_winking_eye