Using lookups

Posts   
 
    
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 19-Jul-2006 11:07:51   

Lets say I have two tables related with 1:n (Master.Id->Child.MasterId) Master Id

Child Id MasterId

And I need some sort of lookup control for displaying and picking a proper master. If I set key value for this lookup to be "Master.Id" then Child.MasterId is properly read and set IOW everything works. But. Child.Master (related entity) is not populated and remains null. So, what is the proper way to have set both MasterId field and Master entity at same time (using lookup control)?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 19-Jul-2006 12:01:57   

when the selected index changes -> fetch the related entity and set the child's reference to master to that fetched entity. You then automatically get the FK in child set to the pk of the master.

You could also fetch the entities in the lookup. which avoids you to fetch master entities on the fly simple_smile

Frans Bouma | Lead developer LLBLGen Pro
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 19-Jul-2006 12:18:04   

Otis wrote:

when the selected index changes -> fetch the related entity and set the child's reference to master to that fetched entity. You then automatically get the FK in child set to the pk of the master.

You could also fetch the entities in the lookup. which avoids you to fetch master entities on the fly simple_smile

Aha, ok. I have to set the reference manually. No problems there. Just checking :-). Thanks Frans.

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 19-Jul-2006 12:40:21   

I think I will automate two approaches:

  • The one you suggested (I'll hook MasterId property changed event and assing an entity (I have in context) to the Master property
  • I'll remove Browsable(false) on Master property and bind to Master property directly (of course I would have to load related master records along child records, too)

Ah, btw I am on "adapters" :-)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 19-Jul-2006 13:14:13   

You can use the trick I use in the complex databinding example now available on the website simple_smile

Frans Bouma | Lead developer LLBLGen Pro