Can anyone please help me with this scenario?:
I have LLBLGenPro v2.0 beta generated code (adapter) and I'm using VS.NET 2005. I have successfully managed to get an EntityCollection of "ProductEntity" objects binding to a GridView but a ProductEntity has a ManufacturerEntity object as a property. The ProductEntity also has a ManufacturerId as per the sql table but what I want to show in the GridView is the Name property of that ManufacturerEntity object within the ProductEntity.
Any ideas how I can use a BoundField or TemplateField to drill down to the ManufacturerEntity object and acheive this?
Code below shows how I've attempted to explicitly bind in the GridView, also adding the prefetch for Manufacturer in the ldsProduct_PerformSelect handler.
code is here:
<cc1:LLBLGenProDataSource2
ID="ldsProduct"
runat="server"
AdapterTypeName="MyApp.DAL.DatabaseSpecific.DataAccessAdapter, MyApp.DALDBSpecific"
DataContainerType="EntityCollection"
EntityFactoryTypeName="MyApp.DAL.FactoryClasses.ProductEntityFactory, MyApp.DAL"
OnPerformSelect="ldsProduct_PerformSelect">
</cc1:LLBLGenProDataSource2>
<asp:GridView
ID="grvProductList" runat="server" CssClass="ListGrid"
AlternatingRowStyle-CssClass="EvenRow" GridLines="None"
AllowPaging="True" ShowFooter="True"
AutoGenerateColumns="False" DataSourceID="ldsProduct" DataKeyNames="Id">
<EmptyDataTemplate>
No data found.
</EmptyDataTemplate>
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:TemplateField>
<ItemTemplate>
<%# ((ManufacturerEntity)((ProductEntity)Container.DataItem).Manufacturer).Name%>
</ItemTemplate>
</asp:TemplateField>
<asp:CheckBoxField DataField="IsShippable" HeaderText="IsShippable" SortExpression="IsShippable" />
</Columns>
<AlternatingRowStyle CssClass="EvenRow" />
</asp:GridView>
I end up getting an "Object reference not set to an instance of an object" error
Thanks
Luke