Search code examples
c#asp.netentity-frameworkrepeaterstrong-typing

Entity Framework class in ItemType not showing fields in repeater


I am using Entity Framwework 6 I have a table named Action which I want it to be bound to a repeater

<asp:Repeater ID="rpAction" runat="server" ItemType="Action">
    <ItemTemplate>
        <div>
            <%# Item.ActionID %>
        </div>
    </ItemTemplate>
</asp:Repeater>

In the code-behind:

 var context = new FPSDB_newEntities();    
 rpAction.DataSource = (from a in context.Actions select a).ToList();
 rpAction.DataBind();

Now it is giving be a compile time error:

Action does not contain a definition of ActionID

Although, ActionID is one of the fields in Action Table

When I browse the field, it shows some methods but not the fields of the Action table as shown below.

enter image description here

Also here is the image where one can see the table definition enter image description here The same code is running fine for other tables in my SQL server Database. Can anyone solve this problem thanks


Solution

  • The error is due to a conflict between the type of your table Action and the .Net type Action<T>.

    You can see it because Intellisense suggests you all methods available for Action<T>.

    https://msdn.microsoft.com/en-us/library/018hxwa8(v=vs.110).aspx

    The thing, you can do is to rename your table (Code-First) or to rename the the table-type it in the EDMX (Database-First)

    EDIT: Another solution is to use the fully qualified type name of your table Action to avoid the name conflict, like this:

    <asp:Repeater ID="rpAction" runat="server" ItemType="MyNamespace.Action">