Many-to-many best practices?

Posts   
 
    
morrisb
User
Posts: 13
Joined: 24-Jun-2008
# Posted on: 08-Dec-2008 14:06:57   

Hello, I'm relatively new to LLBLGen and I've been wondering about the best way to work with entities generated from many-to-many tables. I've had a look through the documentation but couldn't find anything specifially relating to this.

I'm building a case management application. In my database I have a Matter table and a Client table - they are associated through a MatterClient table, which is many to many. So many Matters can have many Clients (and vice versa). I have generated MatterEntity, ClientEntity and MatterClientEntity objects.

What I would like to do is add to the Matter's ClientCollection via MatterClient - something like this:

MatterEntity m = new MatterEntity(389); ClientEntity c = new ClientEntity(273); m.ClientCollectionViaMatterClient.Add(c); m.ClientCollectionViaMatterClient.SaveMulti(true);

But I don't seem to get a new MatterClient in the database.

Do I have to do the work of specifically creating a MatterClient object? And if so, do I then need to add it to the Matter.MatterClient and to the Client.MatterClient collections?

Thanks!

LLBLGen Pro 2.6 Final, SelfServicing, .Net 3.5, SQL Server 2005

morrisb
User
Posts: 13
Joined: 24-Jun-2008
# Posted on: 08-Dec-2008 15:11:45   

Ah... the m:n colections are read-only: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=3583

So it looks like I will need to create the intermediate object and refetch either side... not great if they're databound to my Windows front-end. Ho hum.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 08-Dec-2008 15:39:36   

Please check the last example in the doc's section Tutorials and examples - How do I ... ? How do I add an entity A to an entity B's collection of A's if A and B have an m:n relation ?

Another example in the same page is: "How do I create a m:n relation between two entity objects?"

morrisb
User
Posts: 13
Joined: 24-Jun-2008
# Posted on: 08-Dec-2008 16:27:56   

Thanks!