Welcome to the Xceed Community | Help
Community Search  

Master Detail - Linq to SQL - is it posible?

Sort Posts: Previous Next
  •  06-25-2008, 8:35 AM Post no. 13193

    Master Detail - Linq to SQL - is it posible?

    I have a linq to sql dbml file with a tblEquipment table and a tblEquipmentLog table with a one-to-many relationship. I want to drill down to see the equipmentlog for each piece of equipment.

    As in the linq to sql example i query the databse like this:

            public rglEquipmentDataContext db = new rglEquipmentDataContext();       

            private IEnumerable<tblEquipment> eQuery = null;
            public IEnumerable<tblEquipment> qEquipment
            {
                get
                {
                    if (eQuery == null)
                    {
                        eQuery = from e in db.tblEquipments
                                  select e;
                    }
                    return eQuery;
                }
            }

     In my XAML i have CollectionViewSource like this.

            <xcdg:DataGridCollectionViewSource x:Key="cvsEquipment"
                                               Source="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=qEquipment}"
                                               AutoFilterMode="And" 
                                               DistinctValuesConstraint="Filtered">
     

     I've added AutoCreateDetailConfigurations="True" to the grid

    I've also added                

    <xcdg:DataGridControl.DetailConfigurations>
                        <xcdg:DetailConfiguration RelationName="tblEquipment_tblEquipmentLog"
                                      Title="Equipment Log">
                            <xcdg:DetailConfiguration.Columns>
                                <xcdg:Column FieldName="eqlID"
                               Visible="False" />
                                <xcdg:Column FieldName="eqlUser"
                               Visible="True" />
                            </xcdg:DetailConfiguration.Columns>
                        </xcdg:DetailConfiguration>
                    </xcdg:DataGridControl.DetailConfigurations> 

     What else do i need to do to make it work.

    Thanks in advnace for you help.

    Filed under: ,
  •  06-25-2008, 8:57 AM Post no. 13194 in reply to 13193

    Re: Master Detail - Linq to SQL - is it posible?

    Hi,

    In your dbml generated .cs file you should see somewhere :

    public EntitySet<tblEquipment> tblEquipmentLog {

    You should add the following property :

    [Xceed.Wpf.DataGrid.PropertyRelation]

    public EntitySet<tblEquipment> tblEquipmentLog {

    Also leave out the RelationName in your DetailConfigurations !

    Works ok in my app, should work in yours as well.

    (Downside : if yoy regenerate your dbml file you'll have to reenter the property as well., but it is on xceed's to do list

    to automatically detect these master/detail in linq (I think))

     

     

  •  06-25-2008, 9:19 AM Post no. 13195 in reply to 13194

    Re: Master Detail - Linq to SQL - is it posible?

    Wow that worked.  I new it would be easy to do.  Thanks for you help.

    It's editable too.

     

    Any ideas on how to make some of the fields of the child not visible and adding the autofilter?

    I'll need to figure out adding comboboxes to the child too at some point.  

     

    Thanks again for the help.

     

    Darren

  •  06-25-2008, 9:42 AM Post no. 13196 in reply to 13195

    Re: Master Detail - Linq to SQL - is it posible?

    Hi,

    for making some of the child columns not visible :

    <xcdg:DetailConfiguration.Columns>

    <xcdg:Column FieldName="xx" Visible="False" />

    <xcdg:Column FieldName="yy" Visible="False" />

    ...

    </xcdg:DetailConfiguration.Columns>

    AutoFilter on the child grid, I do not know, but if somebody does please tell, I'm interested as well !

    Henk

  •  06-25-2008, 9:50 AM Post no. 13199 in reply to 13196

    Re: Master Detail - Linq to SQL - is it posible?

    Hi,

    I forgot to mention that the RelationNAme should be

    RelationName="tblEquipmentLog", but I figure you have done that, since you got it working.

    Henk

  •  06-25-2008, 10:05 AM Post no. 13201 in reply to 13196

    Re: Master Detail - Linq to SQL - is it posible?

    Sorry but i can't quite figure out where to put what you've suggested.  IS this right?  It's not working anyway.

    Thanks.          

    <xcdg:DataGridControl Name="dataGridControl1" ItemsSource="{Binding Source={StaticResource cvsEquipment}}" AutoCreateColumns="True" CellEditorDisplayConditions="MouseOverRow, Always" Grid.Column="1" AutoCreateDetailConfigurations="True">
                    <xcdg:DataGridControl.Resources...>
                    <xcdg:DataGridControl.View...>
                    <xcdg:DataGridControl.Columns...>
                    <xcdg:DataGridControl.DetailConfigurations>
                        <xcdg:DetailConfiguration>
                            <xcdg:DetailConfiguration.Columns>
                                <xcdg:Column FieldName="eqlID" Visible="False" />
                                <xcdg:Column FieldName="eqID" Visible="False" />
                            </xcdg:DetailConfiguration.Columns>
                        </xcdg:DetailConfiguration>
                    </xcdg:DataGridControl.DetailConfigurations>

    </xcdg:DataGridControl>

  •  06-25-2008, 10:09 AM Post no. 13202 in reply to 13199

    Re: Master Detail - Linq to SQL - is it posible?

    Henk:

    Hi,

    I forgot to mention that the RelationNAme should be

    RelationName="tblEquipmentLog", but I figure you have done that, since you got it working.

    Henk

     

    I didn't do that actually because you said remove the relation name initially.

    I'll put it back in now.  thats probably why it's not working.

    Thanks

  •  06-25-2008, 10:15 AM Post no. 13203 in reply to 13202

    Re: Master Detail - Linq to SQL - is it posible?

    Yep works now.  thanks again.

     Have you anyy ideas about adding a record to the child?

     

    Darren

  •  06-27-2008, 5:51 AM Post no. 13260 in reply to 13203

    Re: Master Detail - Linq to SQL - is it posible?

    Does anybody know how to add a record to the details?

    I've added and insertion row into the details view but i get this error.

    An attempt was made to add a new data item to a source that does not support insertion.

    Here is 

                    <xcdg:DataGridControl.DetailConfigurations>
                        <xcdg:DetailConfiguration RelationName="tblEquipmentLogs" Title="Issue Log" >
                            <xcdg:DetailConfiguration.Columns>
                                <xcdg:Column FieldName="eqlID" Visible="False"  />
                                <xcdg:Column FieldName="eqID" Visible="False" />
                                <xcdg:Column FieldName="eqlDatetime" Title="Date" />
                                <xcdg:Column FieldName="eqlUser" Title="User" Width="50"/>
                                <xcdg:Column FieldName="eqlType" Title="Type" Width="50" />
                                <xcdg:Column FieldName="eqlNotes" Title="Notes" Width="450" />
                                <xcdg:Column FieldName="tblEquipment" Visible="False" />
                            </xcdg:DetailConfiguration.Columns>
                            <xcdg:DetailConfiguration.Footers>
                                <DataTemplate>
                                    <xcdg:InsertionRow />
                                </DataTemplate>
                            </xcdg:DetailConfiguration.Footers>
                        </xcdg:DetailConfiguration>
                    </xcdg:DataGridControl.DetailConfigurations>

     

  •  06-27-2008, 8:06 AM Post no. 13264 in reply to 13260

    Re: Master Detail - Linq to SQL - is it posible?

    Hi,

      This is because LinqToSQL objects for relations do not implement IBindingList by default...

      Jenny has built a special LinqToSQL detail description that calls GetNewBindingList() and uses its output as the source for details.

      You can find it at:

      http://doc.xceedsoft.com/products/XceedWpfDataGrid/Creating_a_custom_detail_description.html

    Marc Laroche
    Software Developer
    Xceed Software Inc.


    I don’t suffer from insanity, I enjoy every minute of it. - Unknown
  •  06-30-2008, 9:04 AM Post no. 13307 in reply to 13264

    Re: Master Detail - Linq to SQL - is it posible?

    Thanks for the help.

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.