1

新しく挿入されたレコードの自動生成 ID を取得しようとしています。C# コード ビハインドを使用して、SQL データベースで簡単なサンプル プロジェクトを作成し、次のコードを使用して値を正常に取得することができました。しかし、私の作業中のプロジェクトでは、Intellisense は必要なプロパティを提供しません。実際、データベースに存在するプロパティは表示されません。つまり、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>

私は自分の作業プロジェクトで何が違うのか途方に暮れています。

4

0 に答える 0