如何使用 FormView 插入复杂的实体框架对象

发布于 2024-09-05 05:05:21 字数 101 浏览 8 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁人与我共长歌 2024-09-12 05:05:21

经过更多研究后,问题似乎出在 EntityDataSourceView 的 ConvertProperties 方法中。
使用反射器,我发现问题出在以下行:(

PropertyDescriptor pd = propertyDescriptors.Find(str, false);

此代码行获取插入的属性名称,并将其转换为描述符)

当 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:

PropertyDescriptor pd = propertyDescriptors.Find(str, false);

(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.

世态炎凉 2024-09-12 05:05:21

其实是有解决办法的。将两个物体合二为一。创建一个包含两个对象的所有字段的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文