使用 ASP.NET MVC 2 和模型与 ADO.NET EntityCollections 绑定

发布于 2024-10-03 19:26:54 字数 428 浏览 0 评论 0原文

我发现了一个关于如何使用模型绑定和列表的很棒的教程,MVC2 中的可编辑网格/列表绑定。它展示了如何创建包含 List 类型列表的对象。但是当我使用 ADO.NET 实体数据模型时,我无法做到这一点:

SomeEntityCollection[i]

因此我无法完成教程中所做的事情。

有办法解决这个问题吗?如果可能的话,也许让 ADO.NET 使用列表来代替?

I found a great tutorial on how to use Model Binding and List, Editable Grid / List Binding in MVC2. It shows how to create objects containing lists of type List<T>. But when I use the ADO.NET entity data model I cannot make the this:

SomeEntityCollection[i]

And thereby I can not make what is done in the tutorial.

Is there a way to work around this? Maybe make the ADO.NET use lists instead, if that's possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

赠佳期 2024-10-10 19:26:54

我发现从 ADO.NET 映射到模型的最佳方法是使用 AutoMapper。这是一种形式化结构之间映射的非常优雅的方式。

从他们的网站:

AutoMapper 使用流畅的配置 API 来定义对象到对象映射策略。 AutoMapper 使用基于约定的匹配算法将源值与目标值进行匹配。目前,AutoMapper面向模型投影场景,将复杂的对象模型扁平化为DTO和其他简单对象,其设计更适合序列化、通信、消息传递,或者只是域和应用层之间的反腐败层。

The best way I have found to map from ADO.NET to models is to use AutoMapper. It's a very elegant way to formalize mapping between structures.

From their site:

AutoMapper uses a fluent configuration API to define an object-object mapping strategy. AutoMapper uses a convention-based matching algorithm to match up source to destination values. Currently, AutoMapper is geared towards model projection scenarios to flatten complex object models to DTOs and other simple objects, whose design is better suited for serialization, communication, messaging, or simply an anti-corruption layer between the domain and application layer.

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