Relation on 2 Tables

Posts   
 
    
Slowhand
User
Posts: 96
Joined: 07-Mar-2006
# Posted on: 20-Apr-2006 09:51:49   

I don´t know how to the resultset of the data in 2 tables. Here´s my code:



DataAccessAdapter dataAdapter = new DataAccessAdapter();
IRelationPredicateBucket relation = new RelationPredicateBucket();
relation.Relations.Add(DispoEntity.Relations.DispkiEntityUsingNrdiNrde);
relation.PredicateExpression.Add(PredicateFactory.CompareValue(DispFieldIndex.Nrdi, ComparisonOperator.Equal, 377));
EntityCollection eCollection = new EntityCollection(new DispEntityFactory());
dataAdapter.FetchEntityCollection(eCollection, relation);



foreach (DispEntity d in eCollection)
{
      //here I get all the DispEntity´s, but how can I get the
      // values from the related table ""Dispki"
     // do I have to create an EntityCollection for Dispki too ?  
    //  I would like to get access to Dispki in this way:

      foreach( DispEntity.Dispki dki in someCollection ) ...            

 }

Is there a way to do this with LLBLGen Pro ?

Thank you for your help, Slowhand

Slowhand
User
Posts: 96
Joined: 07-Mar-2006
# Posted on: 20-Apr-2006 13:40:47   

I can do this with IPrefetchPath2(Adapter):


EntityCollection eColl = new EntityCollection(new DispEntityFactory());
IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.DispEntity);
prefetchPath.Add(DispEntity.PrefetchPathDispprint);
IRelationPredicateBucket filter = new RelationPredicateBucket();

filter.PredicateExpression.Add(PredicateFactory.CompareValue(DispFieldIndex.Nrdispo, ComparisonOperator.LessEqual, textBox1.Text));
DataAccessAdapter adapter = new DataAccessAdapter();
            
adapter.FetchEntityCollection(eColl , filter, prefetchPath);

dataGridView1.DataSource = eColl ;


The Problem at this way is, that only the data of the DispEntity is loaded to the grid. But what about the related data of the Dispoprint entity. In the documentation ist described that there should be a + where I can open the related entities.

Why couldn´t see I an "+" in the datagrid ( begin of the row) ?

Slowhand

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Apr-2006 15:15:40   

To have properties from the related entity shown in the datagrid you may do one of the following:

1- From the LLBLGen Designer use the Field on related field sub-tab found in the Entity -> properties, to map those fields you need from the related entity into fields in your main entity. (Note that those mapped fields will only be filled using the prefetchPath)

2- If you only need those entities for a read-Only purposes, instead of Entity Collection use a TypedList, dynamicList or TypedView to fecth fields from different related entities.

Slowhand
User
Posts: 96
Joined: 07-Mar-2006
# Posted on: 20-Apr-2006 17:07:04   

yes, thanks for the answer, but when I have a 1:n Relation I get this view in the datagrid:

CustomerNr AdressStreet 1 Street_1 1 Street_2

This is of course correct and means that one customer has 2 different adresses. But is there a way to create this view in the grid:

Closed:

     + 1 (Customer)

Open:

     - 1(CustomerNr)
         Street_1
         Street_2   
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Apr-2006 09:49:32   

In my experience with VS 2003, C# & windows forms.

The datagrid will automatically show a plus (+) column showing the inner objects.

Please refer to the following link: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconIntroductiontotheDataGridControl.asp

danilojazz
User
Posts: 1
Joined: 02-Aug-2006
# Posted on: 02-Aug-2006 21:27:19   

hum... I'm wondering in order it but before I have some questions to be cleared: - I'm using de demo version, and I couldn't to bind the categoryName in my datagrid (web application project) and I need to show it to supervisor, actually I have to show them why spend money on this... and they asked me a example using a Inner Join... My question is: How can I bind a datagrid from Northwind with Products and CategoryName from Categories related one each other... Could some of you gimme a example how to use the typedList? Could u tell me if has any level of implementation between adapter and selfServicing?

tks in advance... If I wasn't clear enough, let me know...

best regards from Brazil! Danilo Lima.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 03-Aug-2006 07:59:35   

TypedLists are dataTables

So first ytou should use the designer to create your TypedList (define which fields it should contain and from which tables)

That in your code you would only need to fetch this typedList and bind it to a DataGrid as if it was dataTable.

To fetch a TypedList please refer to the examples in the LLBLGen Pro manual documentation Using the generated code -> Adapter/SelfServicing -> Using TypedViews, TypedLists and Dynamic Lists -> Using the typed list classes