FormView控件与EntityDataSource和DropDownList中给出" A属性名称“{0}”不是实体发现..." [英] FormView with EntityDataSource and DropDownList gives "A property names '{0}' was not found on the entity ..."

查看:158
本文介绍了FormView控件与EntityDataSource和DropDownList中给出" A属性名称“{0}”不是实体发现..."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:当我尝试用做一个更新的 EntityDataSource FormView控件有一个< ASP:DropDownList的> 链接到另一个表,页面加载罚款与正确的设置,但在更新我收到此错误信息:

The problem: when I try to do an update using an EntityDataSource and a FormView that has an <asp:DropDownList> linking to another table, the page loads fine with the proper setting, but on update I get this error message:

Vendor.VendorId没有对实体插入,更新过程中发现一个名为的属性,删除等操作。检查以确保指定为绑定前pressions属性可用于数据源。

环境和code:使用Visual Studio 2010,实体框架4,ASP.NET Web表单,和SQL Server 2008前preSS

The environment and code: using Visual Studio 2010, Entity Framework 4, ASP.NET web forms, and SQL Server 2008 Express.

我有两个表;一个部分表和供应商表。在部分表中有一个 VENDORID 列其链接到供应商表,并允许为 NULL 。它是由实体框架包裹着。

I have two tables; a Part table and a Vendor table. The Part table has a VendorId column which links to the Vendor table, and it is allowed to be NULL. It is wrapped by Entity Framework.

的作品的一部分:这里的 EntityDataSource

<asp:EntityDataSource ID="PartEntityDataSource" runat="server" 
    ConnectionString="name=PartDBEntities" 
    DefaultContainerName="PartDBEntities" EnableFlattening="True" 
    EntitySetName="Parts" 
    EntityTypeFilter="Part" Where="it.PartId = @PartId" 
    EnableUpdate="True" EnableInsert="True" Include="Vendor">
    <WhereParameters>
        <asp:QueryStringParameter Type="Int64" DefaultValue="null" Name="PartId" 
            QueryStringField="partid" />
        </WhereParameters>
</asp:EntityDataSource>

(注意:我试着 EnableFlattening 开和关)

这是通过链接到 FormView控件

<asp:FormView ID="PartEditorFormView" runat="server"
    DataSourceID="PartEntityDataSource"
    DataKeyNames="PartId">

请注意,我强迫 FormView控件修改模式或插入模式取决于查询字符串参数。

Note that I am forcing the FormView into Edit mode or Insert mode depending on a query string parameters.

如果没有的DropDownList ,我能够在数据库中创建和更新记录。

Without the DropDownList, I am able to create and update records in the database.

不起作用部分:现在的的DropDownList 。首先出现的是一个新的 EntityDataSource

The part that doesn't work: now for the DropDownList. First there is a new EntityDataSource:

<asp:EntityDataSource ID="VendorEntityDataSource" runat="server"
    ConnectionString="name=PartDBEntities"
    DefaultContainerName="PartDBEntities" EnableFlattening="False"
    EntitySetName="Vendors" />

和则的DropDownList EditTemplate ,使用的在模板字段转换空

<asp:DropDownList ID="EditVendorDDL" runat="server" 
    DataSourceID="VendorEntityDataSource" 
    DataTextField='CompanyName' 
    DataValueField='VendorId'
    AppendDataBoundItems="True"
    SelectedValue='<%# Bind("Vendor.VendorId") %>'>
        <asp:ListItem Selected="True" Value="">(none)</asp:ListItem>
</asp:DropDownList>

正如我前面所说,最初的页面显示就好了;在的DropDownList 有正确的条目,并正确的供应商设置为正确的值。只需点击更新按钮导致上述错误。

As I said above, the initial page displays just fine; the DropDownList has the right entries in it and the correct vendor is set to the correct value. Just clicking on the Update button causes the above error.

下面是堆栈跟踪的相关部分:

Here is the relevant part of the stack trace:

[InvalidOperationException异常:插入,更新过程中对实体未找到名为Vendor.VendorId'的属性,删除等操作结果
  检查以确保指定的属性作为约束性前pressions是
  提供给数据源。]结果
  System.Web.UI.WebControls.EntityDataSourceView.ConvertProperties(IDictionary的
  值,PropertyDescriptorCollection的PropertyDescriptor,
  ParameterCollection中referenceParameters,Dictionary`2 convertedValues​​)
  +263结果
  System.Web.UI.WebControls.EntityDataSourceView.ExecuteUpdate(IDictionary的
  键,IDictionary的值,IDictionary的oldValues​​)256结果
  System.Web.UI.DataSourceView.Update(IDictionary的键,IDictionary的值,IDictionary的oldValues​​,DataSourceViewOperationCallback回调)+95

[InvalidOperationException: A property named 'Vendor.VendorId' was not found on the entity during an insert, update, or delete operation.
Check to ensure that properties specified as binding expressions are available to the data source.]
System.Web.UI.WebControls.EntityDataSourceView.ConvertProperties(IDictionary values, PropertyDescriptorCollection propertyDescriptors, ParameterCollection referenceParameters, Dictionary`2 convertedValues) +263
System.Web.UI.WebControls.EntityDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +256
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +95

我希望这是足够的信息!

I hope that is enough information!

推荐答案

如果不是的SelectedValue虽然是从PartEntityDataSource的角度来看,因为VendorEntityDataSource不具约束力的约束控制整体数据,你需要使用&LT;%#绑定(厂商ID)%方式&gt; 而不是

Shouldn't the selectedvalue though be from the PartEntityDataSource perspective, because the VendorEntityDataSource isn't binding the overall data bound control, you need to use <%# Bind("VendorID") %> instead.

心连心。

这篇关于FormView控件与EntityDataSource和DropDownList中给出&QUOT; A属性名称“{0}”不是实体发现...&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆