Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Master detail relations in Linq to sql

Posted on 2009-04-15
1
Medium Priority
?
1,270 Views
Last Modified: 2013-11-11
how to build that? in datatables I used to have something like this: (code bellow)

msBindSource.DataSource = ds
        msBindSource.DataMember = msDt.TableName
        rgridview.DataSource = msBindSource
        
        detailBindSource.DataSource = msBindSource
       detailBindSource.DataMember = "msRelationStr" -> that is the relation name

Open in new window

0
Comment
Question by:TheSilverBullet
[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
1 Comment
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 1600 total points
ID: 24154581
Hi TheSilverBullet;

The best way to do a Master/Detail with Linq to SQL is to let the IDE environment build the underneath plumbing for you. I will use the Microsoft Northwind database to show how to do it.

1. Add a Linq to SQL Class to your project.
2. Once the designer is displayed add the Orders and Order_Details table to the design surface.
3. Save and compile the project.
4. Add a DataSource object to your project By clicking on the Menu -> Data -> Add New DataSource.
5. In the DataSource Window select Object and click on the Next button.
6. Expand the Project Name node and then Expand the node with the Project Name again.
7. Now select the Master table name, in this case it is Orders.
8. Click on the Finish button.
9. Open the DataSource window if it is not already displayed.
10. Drag the Orders table on to the form. This will add one BindingSource component named OrdersBindingSource and a BindingNavigator called OrdersBindingNavigator as well as the Master DataGridView with all plumbing connected for you.
11. Now drag the Order_Details table on to the form from the DataSource window. This will add a BindingSource component called Order_DetailsBindingSource to the form and the Details DataGrridView.
12. Now query the data source as shown in the code snippet below and that is it.
13. Run the project.

Fernando
Public Class Form1
 
    Private Sub Form1_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load
 
        Dim db As New NorthwindDataContext()
 
        OrdersBindingSource.DataSource = From order In db.Orders _
                                         Select order
 
    End Sub
 
End Class

Open in new window

0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

604 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