Custom Detail in Linq-to-SQL Master-Detail DataGridViews

Posted by Andres on Stack Overflow See other posts from Stack Overflow or by Andres
Published on 2010-06-14T08:02:15Z Indexed on 2010/06/14 14:02 UTC
Read the original article Hit count: 295

Hi, looking for a way to create Linq-to-SQL Master-Detail WinForms DataGridViews where the Detail part of the Linq query is a custom one. Can do fine this:

DataClasses1DataContext db = new DataClasses1DataContext(".\\SQLExpress");
var myQuery = from o in db.Orders select o;
dataGridView1.DataSource = new BindingSource()
{
    DataSource = myQuery
};
dataGridView2.DataSource = new BindingSource()
{
    DataSource = dataGridView1.DataSource,
    DataMember = "OrderDetails"
};

but I'd like to have the Detail part under my precise control, like

var myQuery = from o in db.Orders join od in db.OrderDetails  
on o.ID equals od.OrderID into MyOwnSubQuery select o;

and use it for the second grid:

dataGridView2.DataSource = new BindingSource()
{
  DataSource = dataGridView1.DataSource,
  DataMember = "MyOwnSubQuery" // not working...
};

the real reason I want it is a bit more complex (I'd like to have the Detail part to be some not-pre-defined join actually), but I'm hoping the above conveyed the idea.

Can I only have the Detail part as a plain sub-table coming out of the pre-defined relation or can I do more complex stuff with the Detail part? Does anyone else feel this is kind of limited (if the first example is the best we can do)? Thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms