Grid from two or more tables

Posts   
 
    
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 25-Jun-2010 16:55:48   

Hi, I have a datagrid on winform in which I want to display the following

  1. State ID from table state
  2. Description from table state

  3. Country ID from table country

  4. Description from table country

Relation is state.countryid = country.countryid and filter by flag=0 in both state and country tables. Tried as follows but I do not know the exact way of doing it.

private void PopulateGrid() // Load Data { #region Fill Grid with Database Table.Column Names and order

        var statedatasource = new EntityCollection<StateEntity>(new StateEntityFactory());
        var bucketstate = new RelationPredicateBucket();

        using (var stateadapter = new DataAccessAdapter())
        {

            stateadapter.FetchEntityCollection(entityCollectionstate, null);

            bucketstate.PredicateExpression.Add(StateFields.Flag == ClubCentricBISpecific.StandardFlag.recordvalidflag); // Filter by recordvalidflag
            bucketstate.PredicateExpression.Add(StateFields.CountryId == CountryFields.CountryId);
            bucketstate.PredicateExpression.Add(CountryFields.Flag == ClubCentricBISpecific.StandardFlag.recordvalidflag); // Filter by recordvalidflag

            stateadapter.FetchEntityCollection(statedatasource, bucketstate, 0,
                                          new SortExpression(StateFields.Description | SortOperator.Ascending));

            dgridstate.DataSource = statedatasource;
            stateadapter.CloseConnection();



        }

Thanks and advance !

Regards, Shekar

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Jun-2010 21:39:26   

Ok.

  1. If you will filter on the related collection you need to add such relation to your bucket (Read more...).
  2. If you plan to show additional information from the related collection fields you need to use PrefetchPaths so the related entities are fetched as well.
  3. Once the entities are fetched you need to show the info in the grid. To show the info from the related entities you must create custom properties that access the related fields or create Fields Mapped on Related Entities on LLBLGen Designer. (let me know if you need help on this).
David Elizondo | LLBLGen Support Team
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 26-Jun-2010 07:47:56   

daelmo wrote:

Ok.

  1. If you will filter on the related collection you need to add such relation to your bucket (Read more...).
  2. If you plan to show additional information from the related collection fields you need to use PrefetchPaths so the related entities are fetched as well.
  3. Once the entities are fetched you need to show the info in the grid. To show the info from the related entities you must create custom properties that access the related fields or create Fields Mapped on Related Entities on LLBLGen Designer. (let me know if you need help on this).

I tried this but no luck yet .

var state = new EntityCollection(new StateEntityFactory()); IPrefetchPath2 prefetchPath = new PrefetchPath2((int) EntityType.StateEntity); prefetchPath.Add(StateEntity.PrefetchPathCountry); IRelationPredicateBucket filter = new RelationPredicateBucket(); var adapter = new DataAccessAdapter(); adapter.FetchEntityCollection(state, filter, prefetchPath); dgridstate.DataSource = state;

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 26-Jun-2010 11:10:26   

What didn't work, what error did you get? please be specific.

Frans Bouma | Lead developer LLBLGen Pro
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 26-Jun-2010 13:37:05   

Otis wrote:

What didn't work, what error did you get? please be specific.

No Error. Am unable to display in grid the following data

  1. State.Description and Country.description where state.countryid=country.countryid

(edit) If you keep re-posting the post, I'll keep removing it. We have support queues, it's automatically added to those support queues, and your question is in that queue. We'll get to you a.s.a.p. --Otis

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 28-Jun-2010 06:40:57   

Please show us how you had setup the grid. WinForms or WebForms? Please show me how is the aspx, etc, and how your custom property looks.

(Edit) Example: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=12021

David Elizondo | LLBLGen Support Team
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 28-Jun-2010 06:53:54   

daelmo wrote:

Please show us how you had setup the grid. WinForms or WebForms? Please show me how is the aspx, etc, and how your custom property looks.

It is wingrid. No custom properties

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 28-Jun-2010 07:29:52   

Ok. Then you need to add a Custom Property. On your DBGeneric project add a file that is a partial class of StateEntity:

public partial class StateEntity
{
    public string CountryName
    {
        get
        {
            string toReturn = string.Empty;

            if (Country != null)                
            {
                toReturn = Country.Name;    
            }

            return toReturn;
        }       
    }
}

(Tip: in LLBLGen Designer you can add fields on related entity fields. Then regenerate code and LLBLGen will create this property for you.)

Once you have your custom property you can use that property when you design your grid. Instead of add the CountryId column, you will add CountryName column.

David Elizondo | LLBLGen Support Team
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 28-Jun-2010 07:37:21   

Will try and revert back. Thanks

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 28-Jun-2010 17:49:30   

shekar wrote:

Will try and revert back. Thanks

Thanks it worked. After problem is resolved, it looks so simple. Great support. Thanks again