Binding custom property in Entity Framework

Posted by deverop on Stack Overflow See other posts from Stack Overflow or by deverop
Published on 2010-12-22T02:45:02Z Indexed on 2010/12/22 2:54 UTC
Read the original article Hit count: 525

I have an employee entity in my EF model. I then added a class to the project to add a custom property

public partial class Employee
{
    public string Name
    {
        get { return string.Format("{0} {1}", this.FirstName, this.LastName); }
    }
}

On a aspx form (inside a FormView), I want to bind a DropDownList to the employee collection:

                <asp:Label runat="server" AssociatedControlID="ddlManagerId"
                    Text="ManagerId" />
                <asp:DropDownList ID="ddlManagerId" runat="server" 
                    DataSourceID="edsManagerId" 
                    DataValueField="Id" 
                    DataTextField="Name" 
                    AppendDataBoundItems="true"
                    SelectedValue='<%# Bind("ManagerId") %>'>
                    <asp:ListItem Text="-- Select --" Value="0" />
                </asp:DropDownList>
                <asp:EntityDataSource ID="edsManagerId" runat="server" 
                    ConnectionString="name=Entities" 
                    DefaultContainerName="Entities" 
                    EntitySetName="Employees" 
                    EntityTypeFilter="Employee"
                    EnableFlattening="true">
                </asp:EntityDataSource>

Unfortunately, when I fire up the page, I get an error:

DataBinding: 'System.Web.UI.WebControls.EntityDataSourceWrapper' does not contain a property with the name 'Name'.

Any ideas what I'm doing wrong?

© Stack Overflow or respective owner

Related posts about webforms

Related posts about entity-framework-4