[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Associative table & linq?

Posted on 2011-02-16
5
Medium Priority
?
539 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 41

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 41

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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

649 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