Web窗体的实体框架在代码背后缺少属性

时间:2012-12-07 22:20:32

标签: entity-framework frameworks entity webforms

我正在尝试获取新插入记录的自动生成ID。使用C#代码后,我能够使用我的SQL数据库创建一个快速示例项目,并使用以下代码成功检索了该值。但是在我的工作项目中,Intellisense不会提供我需要的属性,实际上db中不存在任何属性,即在EDS_OnInserted中,找不到“ContactID”:

    protected void EDS_OnInserted(object sender, EntityDataSourceChangedEventArgs e)
    {
        Contact myContact = e.Entity as Contact;
        Label1.Text = "ID = " + myContact.ContactID;
    }

<asp:EntityDataSource ID="EntityDataSource1" runat="server" 
    ConnectionString="name=CEntities" DefaultContainerName="CEntities" OnInserted="EDS_OnInserted" 
    EnableFlattening="False" EnableInsert="True" EntitySetName="Contacts">
</asp:EntityDataSource>
<br />
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="300px" 
    AutoGenerateRows="False" DataKeyNames="ContactID" 
    DataSourceID="EntityDataSource1">
    <Fields>
        <asp:BoundField DataField="ContactID" HeaderText="ContactID" ReadOnly="True" 
            SortExpression="ContactID" />
        <asp:BoundField DataField="LastName" HeaderText="LastName" 
            SortExpression="LastName" />
        <asp:CommandField ShowInsertButton="True" />
    </Fields>
</asp:DetailsView>
<br /><br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

我在工作项目中有所不同。

0 个答案:

没有答案
相关问题