首页 新闻 会员 周边 捐助

ADO.NET entity外键列怎么添加数据?

0
悬赏园豆:100 [已解决问题] 解决于 2010-07-02 08:19

大家好!我用的是 entity,页面控件是一个Telerik的Grid 自动生成增、删、改。编辑页面有一个下拉列表,当点击编辑的时候把数据自动带过来的。DicTypeID是外键,怎么直接绑定外键的列。当我点击添加或编辑提示我找不到该列。不知道怎么解决!!!大家帮看看!!!谢谢!!!!郁闷好几天了。

代码如下:

<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
            AllowAutomaticUpdates="True" DataSourceID="EntityDataSource1" GridLines="None"
            OnItemUpdated="RadGrid1_ItemUpdated" OnInsertCommand="RadGrid1_InsertCommand"
            OnItemCommand="RadGrid1_ItemCommand">
            <MasterTableView AutoGenerateColumns="False" HorizontalAlign="NotSet" CommandItemDisplay="TopAndBottom"
                DataKeyNames="DicID" DataSourceID="EntityDataSource1">
                <Columns>
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                    </telerik:GridEditCommandColumn>
                    <telerik:GridBoundColumn DataField="DicID" HeaderText="DicID" SortExpression="DicName"
                        UniqueName="DicID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="DicDode" HeaderText="DicDode" SortExpression="DicDode"
                        UniqueName="DicDode">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="DicName" HeaderText="DicName" SortExpression="DicName"
                        UniqueName="DicName">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="DicRe" HeaderText="DicRe" SortExpression="DicRe"
                        UniqueName="DicRe">
                    </telerik:GridBoundColumn>                           
                     <telerik:GridDropDownColumn  DataType="System.Guid"  DataField="d_DicType.DicTypeID" DataSourceID="EntityDataSource2"
                        ListTextField="TypeName"  ListValueField="DicTypeID" HeaderText="d_DicType.DicTypeID"
                        SortExpression="d_DicType.DicTypeID" UniqueName="d_DicType.DicTypeID">
                    </telerik:GridDropDownColumn>
                       
                   
                    <telerik:GridButtonColumn HeaderText="Delete" ConfirmText="Delete this product?"
                        ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton"
                        CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
                        <ItemStyle HorizontalAlign="Center" />
                    </telerik:GridButtonColumn>
                </Columns>
                <EditFormSettings EditFormType="Template" ColumnNumber="2" CaptionDataField="RoleName">
                    <EditColumn ButtonType="ImageButton" InsertText="Insert Order" UpdateText="Update record"
                        UniqueName="EditCommandColumn1" CancelText="Cancel edit">
                    </EditColumn>
                    <FormTableStyle CellSpacing="0" CellPadding="2" Height="110px" BackColor="White" />
                    <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" BackColor="White"
                        Width="100%" />
                    <FormTableItemStyle Wrap="False"></FormTableItemStyle>
                    <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
                    <FormTableButtonRowStyle HorizontalAlign="Right"></FormTableButtonRowStyle>
                    <FormTemplate>
                        <table align="center" border="2" cellpadding="2" cellspacing="1" style="width: 100%;
                            border-collapse: collapse;">
                            <tr>
                                <td style="width: 100px; height: 40px">
                                    <telerik:RadTextBox ID="DicID" runat="server" Text='<%# Bind("DicID") %>' Width="150px"
                                        Visible="false">
                                    </telerik:RadTextBox>
                                    DicDode:
                                </td>
                                <td style="height: 30px">
                                    <telerik:RadTextBox ID="RadTextBox_UserName" runat="server" Text='<%# Bind("DicDode") %>'
                                        Width="150px">
                                    </telerik:RadTextBox>
                                </td>
                                <td style="width: 120px; height: 30px">
                                    DicName:
                                </td>
                                <td style="height: 30px">
                                    <telerik:RadTextBox ID="RadTextBox_LoginName" runat="server" Text='<%# Bind("DicName") %>'
                                        Width="150px">
                                    </telerik:RadTextBox>
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 100px; height: 40px">
                                    DicRe:
                                </td>
                                <td style="height: 30px">
                                    <telerik:RadTextBox ID="RadTextBox3" runat="server" Text='<%# Bind("DicRe") %>' Width="150px">
                                    </telerik:RadTextBox>
                                </td>
                                <td style="width: 120px; height: 30px">
                                    DicTypeID:
                                </td>
                                <td style="height: 30px">
                         
                                    
                                    <telerik:RadComboBox ID="ComboBox1" runat="server" DataSourceID="EntityDataSource2"
                                        DataTextField="TypeName" DataValueField="DicTypeID" AppendDataBoundItems="true"
                                        SelectedValue='<%# Bind("DicTypeID") %>'  >
                                    </telerik:RadComboBox>
                                   
                             
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4" align="center">
                                    <asp:Button ID="btnUpdate" runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
                                        Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' />
                                    <asp:Button ID="btnCancel" runat="server" CausesValidation="False" CommandName="Cancel"
                                        Text="Cancel" />
                                </td>
                            </tr>
                        </table>
                    </FormTemplate>
                </EditFormSettings>
            </MasterTableView>
        </telerik:RadGrid>

 

 <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=UnicornDBEntities"
            DefaultContainerName="UnicornDBEntities" EnableDelete="True" EnableInsert="True"
            EnableUpdate="True" EntitySetName="d_DicInfo" EntityTypeFilter="d_DicInfo">
        </asp:EntityDataSource>
    </div>
    <asp:EntityDataSource ID="EntityDataSource2" runat="server" ConnectionString="name=UnicornDBEntities"
        DefaultContainerName="UnicornDBEntities" EntitySetName="d_DicType"
        EntityTypeFilter="d_DicType">
    </asp:EntityDataSource>

bzhyan的主页 bzhyan | 初学一级 | 园豆:82
提问于:2010-06-17 08:48
< >
分享
最佳答案
0

假如a实体中有个外键  关联B实体中的字段  可以在建entity时在A用b实体存储

protected B B1;

        public  B b1
        {
            get { B1; }
            set { OnPropertyChanged("B1", b1, value); B1= b1; }; 
        }

 

 

绑定的时候用B1点出来就行了

收获园豆:100
_____昆 | 菜鸟二级 |园豆:204 | 2010-06-18 16:54
其他回答(1)
0

添加reference的entitykey

圳哥 | 园豆:225 (菜鸟二级) | 2010-06-17 11:50
谢谢你的回答,能详细点吗?大家帮忙看看啊!!!谢谢!!!!
支持(0) 反对(0) bzhyan | 园豆:82 (初学一级) | 2010-06-17 13:28
没有人遇到过这样的问题吗?
支持(0) 反对(0) bzhyan | 园豆:82 (初学一级) | 2010-06-18 07:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册