Databinding to Grid with prefetchpaths working for two tables but not the third?

Posts   
 
    
BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 30-Aug-2007 11:34:09   

Hello

I am using the below code to retrieve a entitycollection to bind to a RadGrid.




 EntityCollection orders = new EntityCollection(new OrderEntityFactory());

            IRelationPredicateBucket bucket = new RelationPredicateBucket();
            bucket.Relations.Add(OrderEntity.Relations.OrderDetailEntityUsingOrderId);
            bucket.Relations.Add(OrderEntity.Relations.UserEntityUsingUserId);
            IEntityField2 ent = EntityFieldFactory.Create(containingObjectName, fieldName);
        
            AddFilterToBucket(datatype, valueTextBox.Text, bucket, ent);
            
            IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.OrderEntity);

            prefetchPath.Add(OrderEntity.PrefetchPathUser);
            prefetchPath.Add(OrderEntity.PrefetchPathOrderDetail);

            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntityCollection(orders, bucket, prefetchPath);
            }

            ReportTest.DataSource = orders;
            ReportTest.DataBind();

When I bind to the radGrid for columns from the UserTable I am setting the datafield to user.columnName, which displays the value, for columns from the order table I am setting the datafield to columnName, which also works, but when I try and bind columns from the OrderDetail Table by using OrderDetail.ColumnName, I get this error:

Unable to find property OrderDetail.ColumnName within a DataItem of type EntityClasses.OrderEntity

I don't understand why I am getting this error only on the order detail table.

What am I doing wrong?

Thanks in advance

Bex

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 30-Aug-2007 11:44:09   

I don't understand why I am getting this error only on the order detail table.

Order.OrderDetail is a collection, isn't it? So there is no such property as Order.OrderDetail.ColumnName

BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 30-Aug-2007 12:02:32   

Hello Walaa

Thank you for the quick reply!

I think I must be missing something?

There are many orderdetails to an order, is this what you mean by its a collection?

I thought I would be able to access the orderdetail columns as it was part of the prefetch and was related to the order.

If this is not the case though what is the best way of getting hold of the columns from the order detail table so I can bind them to the grid along with the information about the actual order and the user?

Thank you

Bex

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 30-Aug-2007 14:47:18   

If this is not the case though what is the best way of getting hold of the columns from the order detail table so I can bind them to the grid along with the information about the actual order and the user?

As you have said, there are many orderDetails for the each order.

So if you are having a grid that display a distinct list of orders and not displaying a JOIN resultSet between Orders & OrderDetails (i.e. an order may be repeated in more than one row to display different OrderDetails information). Then how are you going to display this in the same datagrid?

Best Design approach is to show another Grid to Display the OrderDetails info of the current selected Order frm the Main Grid. (i.e. Master-Details databinding)

BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 30-Aug-2007 15:48:56   

I want to display the order information similar to below

OrderID, OrderDate, Username, OrderDetailProductName 1 10/1/07 Sarah Product1 1 10/1/07 Sarah Product2 1 10/1/07 Sarah Product3 1 10/1/07 Sarah Product3 1 10/1/07 Sarah Product4 2 11/1/07 Scott Product1 2 11/1/07 Scott Product2 3 12/1/07 Emma Product6 4 12/1/07 Sarah Product6

I don't want the master detail format, it is so a report can be produced.

If I add sort of join then will this work? I assumed this was what it was currently doing.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 30-Aug-2007 15:51:48   

Then you should use a TypedList or a DynamicList rather than Entities.

BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 30-Aug-2007 16:07:04   

Can I use .ContainingObjectName against a TypedList or Dynamic List field to get the containing tables Name?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 31-Aug-2007 08:47:57   

Can I use .ContainingObjectName against a TypedList or Dynamic List field to get the containing tables Name?

Why do you need this? Using a DynamicList, you create the fileds/columns yourself in the code, using EntityFields, which have the ContainingObjectName. property

BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 31-Aug-2007 09:50:45   

I never thought of doing it that way.

I need to know what table to fields come from because I dynamically create a bucket depending on what filters the user selects, asnd for this I need to say for example, userfields.username = something.

I tried creating a typed list first time round (not in code) but whn the user selected the fields I couldn't create the filters.

I will try making the typed list in the code from the the fields from the entity that the user selects.

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 31-Aug-2007 10:13:37   

Refer to the LLBLGen Pro docs "Using the generated code ->Adapter/SelfServicing ->TypedViews, TypedLists and Dynamic Lists -> Using dynamic lists"

stefcl
User
Posts: 210
Joined: 23-Jun-2007
# Posted on: 31-Aug-2007 10:18:11   

Hello, Perhaps it's still possible to use entities... The lines of your report are OrderDetails aren't they?

Your current code produces the following

1 Order -----> 1 User | |----------------> many orderDetails

Then why not fetching "OrderDetails" entities directly instead of "Orders"? You can do the filtering by using predicate and relations and also prefetch all the data you need from the order/user tables.

the graph in memory would look like:

1 OrderDetails -----> 1 Order ---------> 1 User/customer

It's exactly what you want to show in you report isn'it?

BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 31-Aug-2007 16:17:40   

Hello, Perhaps it's still possible to use entities... The lines of your report are OrderDetails aren't they?

Your current code produces the following

1 Order -----> 1 User | |----------------> many orderDetails

Then why not fetching "OrderDetails" entities directly instead of "Orders"? You can do the filtering by using predicate and relations and also prefetch all the data you need from the order/user tables.

the graph in memory would look like:

1 OrderDetails -----> 1 Order ---------> 1 User/customer

It's exactly what you want to show in you report isn'it?

Hi stefcl

This is exactly what I want but how would you go about doing the prefecth path to the user table from the order details as the relationship to user is between order and user.

I can add a relation, but am not sure how to prefetch?

thanx

Bex

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 31-Aug-2007 16:25:47   

This is exactly what I want but how would you go about doing the prefecth path to the user table from the order details as the relationship to user is between order and user.

I can add a relation, but am not sure how to prefetch?

You will be fetching the OrderDetails, so you can add a PrefetchPath to the Order entity, and a subPath from the PrefetchPathed Order entity to the User entity.

something that looks like the following: prefetchPath.Add(OrderDetailsEntity.PrefetchPathOrders).SubPath(OrderEntity.PrefetchPathUsers);

Still it will be a burden to display Users data.

BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 31-Aug-2007 16:35:59   

Hi Walaa

Your right, now I am not sure how to get hold of the user details. I am going to try the dynamic lists now and see how I ge on with that.

Thanks

Bex

stefcl
User
Posts: 210
Joined: 23-Jun-2007
# Posted on: 31-Aug-2007 18:37:39   

What's that "Radgrid"?

If you're not using the standard DataGridView but an advanced grid control like the one from devexpress, it might be possible to create an unbound column. The gridview will then call an user defined method at runtime, pass the unbound column reference and the row handle as parameters and you'll have to return the value that should be displayed.

That's what I use when I want to bind a grid control directly to an entityCollection and have to display columns with information from foreign tables, or in some cases, values which are results of a calculation.

In your present case, a typed list is the easiest and most effective way to achieve your goal, but there are situations in which you would need editing and might prefer binding directly to entities in order to use their own validation logic.