Solved

Associative table & linq?

Posted on 2011-02-16
5
537 Views
Last Modified: 2012-05-11
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!
0
Comment
Question by:Nargzul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 34909561
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.

0
 
LVL 1

Author Comment

by:Nargzul
ID: 34909704
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.
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 34916455
It mentions here that you have to first pull it from the database or update:
http://tonesdotnetblog.wordpress.com/2008/08/15/linq-to-entities-disconnected-crud/

and some more samples:
http://naspinski.net/post/Getting-started-with-Linq-To-Entities.aspx
0
 
LVL 1

Accepted Solution

by:
Nargzul earned 0 total points
ID: 34916558
I already pull them from the database before calling the specified method.

I found a work-around, by calling the _context.ObjectStateManager.ChangeRelationshipState
0
 
LVL 1

Author Closing Comment

by:Nargzul
ID: 34949675
found myself the solution
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question