|
Rank: Newbie Groups: Member
Joined: 12/4/2008 Posts: 6
|
I'm using the Entity Framework on .Net 3.5. I'm attempting to access a child table relationship using a Linq query (with the .ToList() method) as a datasource. I'm not able to access the fields of the child table. The Catalogs.Name property (table field) is what I'm trying to access. Debugging shows me that the objects have been populated with the correct values. I'm not able to reference them in the <eo:staticcolumn> tag. Any suggestions? Here is my code: (GRID COLUMNS):
Code: HTML/ASPX
<Columns>
<eo:StaticColumn HeaderText="SKU" DataField="SKU" Width="75" AllowSort="true" AllowResize="true" />
<eo:StaticColumn HeaderText="Catalog" DataField="Catalogs.Name" Width="130" AllowSort="true" AllowResize="true" />
<eo:StaticColumn HeaderText="Product Name" DataField="Name" Width="350" AllowSort="true" AllowResize="true" />
<eo:StaticColumn HeaderText="Price" DataField="Price" AllowSort="true" AllowResize="true" />
<eo:StaticColumn HeaderText="Discount" DataField="Discount" AllowSort="true" AllowResize="true" />
<eo:StaticColumn HeaderText="UOM" DataField="UOM" AllowSort="true" AllowResize="true" />
<eo:StaticColumn HeaderText="Last Modified" DataField="CDAte" AllowSort="true" AllowResize="true" DataFormat="{0:MM/dd/yyyy hh:mm:ss tt}" />
<eo:ButtonColumn CommandName="Modify" DataField="uid" ButtonText="Modify" ButtonType="LinkButton" />
</Columns>
(CODE BEHIND):
Code: C#
IQueryable<Products> oProducts = (from p in _App.DataContext.Products.Include("Catalogs")
select p);
grdMain.DataSource = oProducts.ToList();
grdMain.DataBind();
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
Your code looks fine to us. Since you are pass return value of ToList to the Grid, the Grid sees a list of "p". Whether it can resolve "Catalogs.Name" depends on the type of the object.
The Grid can resolve a "field name" if the object is anything related to a Table. For example, an IDataReader, DataRow or DataRowView, in this case it should correctly resolve "Catalogs.Name". Otherwise it takes DataField as a property name, in that case it won't be able to interpret "Catalogs.Name".
Hope this helps.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 12/4/2008 Posts: 6
|
Hmm... Well, the Catalogs object type is going to be an EntityObject collection. I'm assuming that the Grid control cannot iterate / access the collection, then? I've tried everything I can think of.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
The Grid does iterate a collection. In fact it always iterates through a collection and then try to create a GridRow from each object in the collection. For example, if you have a collection of 10 EntityObjects, your Grid will have 10 rows. Each row would be created from one EntityObject. It is on this row level when Grid tries to check whether it is something related to a DataRow or not.
Hope this clears up.
Thanks
|
|