How do you create a relational object using the LinqDataSource

Posted on 2009-04-19
Medium Priority
Last Modified: 2013-12-17
I am trying to use the LinqDataSource in an ASP.net application.  I have two tables that have a relation between each other through a field call MPI.  I have setup the DataClass.dbml with the two tables and created an association between the two tables.  I had expected that after I did that I could then see all fields from both tables when I dragged the LinqDataSource to the canvas.  When I configured the LinqDataSource I only get the fields from the table that is selected.  How can I access fields from both tables when using the LinqDataSource?
Question by:kwh3856
LVL 11

Expert Comment

ID: 24180113
The selected entity will have a property which represents a collection of the related table instances.
For example, if I have a Sample table and a SampleUnt table which refers to the Sample Table, I could query:

SampleTrackDataContext stdc = new SampleTrackDataContext();
stdc.Log = new DebuggerWriter();
var samples = from s in stdc.Samples
              select s;
foreach (Sample s in samples) {
    foreach (SampleUnit su in s.SampleUnit) {

Open in new window

LVL 64

Expert Comment

by:Fernando Soto
ID: 24181771
Hi Kenny;

Can you post the DBML file and and the code file it created so I can see your DataContext?

LVL 21

Accepted Solution

naspinski earned 2000 total points
ID: 24181932
Relations are already there, you just have to look at them.
For example, if yoiu have a GridView and a LDS that looks at table 'aaa' and it is related to table 'bbb' and you want to see the column 'some_column' in 'bbb' and it is related through the column 'MPI' you could access it like this:

  <%# Eval("column_in_aaa") %> - it will eval columns in aaa normally
  <%# Eval("bbb.some_column") %> - if you want stuff in bbb, you will have to specify it

Open in new window


Author Closing Comment

ID: 31572000
Thank you very much.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

839 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