Link to home
Start Free TrialLog in
Avatar of Nargzul
Nargzul

asked on

Associative table & linq?

Hi!

I've the following schema in my database:

Group:
Id
Name


Rights
Id
Name

AND an associative table
Group_Right
IdRight; IdGroup

Linq generate me for this only two entities, which is right.

I'm using LINQ through wcf, so when I've my objects they are all unlinked and not tracked by the database. I'm using my own POCO entities.

My question is:

When I receive my group and right I should attach to this group, how do I tell linq to save the association?

If have something like

public SaveGroupsRights(Group group, List<Rights> rights){
group.Rights = rights;
DataContext.Save();
}

The association isn't saved in my DB(In this exemple, I've already attached every object to my datacontext).

Thank you!
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Using LinqToSQl or RIA?  

You need to add an association between your tables (either in your EDML or DBML).  Also if you plan on using this client side you need to add load options to include the child table data.

Avatar of Nargzul
Nargzul

ASKER

Nether, Entity Framwork4.0(Linq to entities).

You don't understand, I'm generating this model from the database, which has already all needed foreign keys.

I've already this association, because if I load data from the database, Group_right I set are correctly used to make collections.
ASKER CERTIFIED SOLUTION
Avatar of Nargzul
Nargzul

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nargzul

ASKER

found myself the solution