如何使用 FormView 插入复杂的实体框架对象
我正在尝试使用 formview 来插入新的实体对象(称为 Customer) 客户拥有对另一个名为“地址”的实体的引用。 我怎样才能在同一个表单视图中填写它们呢?
谢谢。
I'm trying to use formview in order to do insert of a new entity object (called Customer)
Customer has a reference to another entity called Address.
How can I fill both of them in the same formview?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过更多研究后,问题似乎出在 EntityDataSourceView 的 ConvertProperties 方法中。
使用反射器,我发现问题出在以下行:(
此代码行获取插入的属性名称,并将其转换为描述符)
当 str = "Address.Address1" 时,函数返回 null。
我查看了 propertyDescriptors.properties,似乎 Address.Address1 不存在。仅存在 Address.ID 和 Address。
我查看了 propertyDescriptors 的数量,似乎没有办法改变它。或者说,问题似乎没有解决办法。
无赖。
After looking more into it, it seems like the problem is in the ConvertProperties method of EntityDataSourceView.
Using reflector I've found out that the problem was in the line:
(this codeline takes the inserted property name, and convert it to a descriptor)
when str = "Address.Address1" the function returns null.
I've took a look at propertyDescriptors.properties and it seems like Address.Address1 doesn't exist. Only Address.ID and Address exist.
I took a look at the population of propertyDescriptors and it seems like there is no way to change that. Or in other words, it seems like there is no solution to the problem.
bummer.
其实是有解决办法的。将两个物体合二为一。创建一个包含两个对象的所有字段的 CustomerViewModel 对象。然后在数据绑定中绑定到 CustomerViewModel。
Actually there is a solution. Flatten the two objects into one. Create a CustomerViewModel object that includes all of the fields of the two objects. Then at databinding bind to the CustomerViewModel.