Entity Framework navigation object not displayed in datagrid

  1. #1

    [Solved]Entity Framework navigation object not displayed in datagrid

    Hi all,

    I am new with ext.net and I am facing a problem.
    I am developping asp.net app with entity framework. So far my model is very simple and attached as image

    Click image for larger version. 

Name:	ext.png 
Views:	163 
Size:	41.1 KB 
ID:	3903

    I would like to display my registries in a grid view, and add the communication_desc (always 'LETTER') corresponding to communication navigation property of entity Registry.

    I successfully did it in regular asp.net, but couldn't find the way to display in an ext.net datagrid the attribute communication_desc of the object communication.

    Find below the code that works in asp.net, but not in ext.

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:EntityDataSource ID="RegistryDataSource" runat="server" ContextTypeName="RegistryModel.RegistryEntities"
                EnableFlattening="False" EntitySetName="Registries" Include="batch_logsheet,Communication"
                ConnectionString="name=RegistryEntities" DefaultContainerName="RegistryEntities">
            </asp:EntityDataSource>
        </div>
        <asp:GridView ID="GridView1" runat="server" DataSourceID="RegistryDataSource" 
            AutoGenerateColumns="False">
            <Columns>
                <asp:BoundField DataField="cover_date" HeaderText="Cover Date" 
                    SortExpression="cover_date" />
                <asp:BoundField DataField="ack_date" HeaderText="Acknowledge Date" 
                    SortExpression="ack_date" />
                <asp:BoundField DataField="source_id" HeaderText="Source" 
                    SortExpression="source_id" />
                <asp:BoundField DataField="cover_type_id" HeaderText="Cover Type" 
                    SortExpression="cover_type_id" />
                <asp:TemplateField HeaderText="Com_desc">
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("Communication.communication_desc") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:GridPanel ID="GridPanel1" runat="server" Height="300">
            <Store>
                <ext:Store ID="Store2" runat="server" DataSourceID="RegistryDataSource">
                    <Reader>
                        <ext:JsonReader IDProperty="registry_id">
                            <Fields>
                                <ext:RecordField Name="cover_date" />
                                <ext:RecordField Name="ack_date" />
                                <ext:RecordField Name="source_id" />
                                <ext:RecordField Name="cover_type_id" />
                                <ext:RecordField Name="received_by" />
                                <ext:RecordField Name="ack_by" />
                                <ext:RecordField Name="ack_type" />
                                <ext:RecordField Name="scanned_data" />
                                <ext:RecordField Name="communication" IsComplex="true"/>
                            </Fields>
                        </ext:JsonReader>
                    </Reader>
                </ext:Store>
            </Store>
            <ColumnModel ID="ColumnModel1" runat="server">
                <Columns>
                    <ext:Column DataIndex="cover_date" Header="Cover Date" />
                    <ext:Column DataIndex="ack_date" Header="Aknowledge Date" />
                    <ext:Column DataIndex="source_id" Header="Source" />
                    <ext:Column DataIndex="cover_type_id" Header="Cover Type" />
                    <ext:Column DataIndex="received_by" Header="Received By" />
                    <ext:Column DataIndex="ack_by" Header="Aknowledge By" />
                    <ext:Column DataIndex="ack_type" Header="Aknowledge Type" />
                    <ext:Column DataIndex="scanned_data" Header="Scanned Data ?" />
                    <ext:Column DataIndex="communication" Header="communication" />
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
    
    
        </form>
    </body>
    </html>
    Basically I'm looking for the equivalent of this partin ext.net:

    <asp:TemplateField HeaderText="Com_desc">
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("Communication.communication_desc") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
    FYI, this is the output I get:

    Click image for larger version. 

Name:	ext2.png 
Views:	143 
Size:	19.6 KB 
ID:	3904

    Thanks a lot
    Last edited by bubu_noumea; Mar 08, 2012 at 4:09 AM. Reason: Solved
  2. #2
    Well I found it, here is the line to put in the JsonReader if anyone needs it:

    <ext:RecordField Name="communication_desc" ServerMapping="Communication.communication_desc" />
    then the column part:

    <ext:Column DataIndex="communication_desc" Header="communication" />
    Cheers !

Similar Threads

  1. Entity Framework SQL question
    By Tookey21 in forum Open Discussions
    Replies: 0
    Last Post: Jul 05, 2012, 2:07 PM
  2. Replies: 0
    Last Post: Dec 01, 2011, 6:34 AM
  3. Replies: 0
    Last Post: Oct 23, 2011, 5:37 PM
  4. Error entity framework and ajaxmethod
    By manelj in forum 1.x Help
    Replies: 4
    Last Post: May 16, 2009, 7:25 AM
  5. Coolite using Entity Framework
    By Zarzand in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Dec 30, 2008, 9:42 PM

Tags for this Thread

Posting Permissions