在 POCO 中使用 AutoMapper?

发布于 2024-09-30 14:50:16 字数 443 浏览 0 评论 0原文

目前,我的 ASP.NET MVC 项目中有一个 POCO 类来处理所有业务逻辑。没有引用其他项目或第三方程序集。

我还在其他项目中使用 AutoMapper 来促进视图模型/实体之间的映射。这是一个很棒的工具,当我更改给定实体上的字段时,它可以为我节省大量时间。

然而,在我的 POCO 类中,有一些在实体之间映射的代码段。业务目的是从一个数据源获取实体并更新另一个数据源。在这里,我手动映射,当我可以使用 AutoMapper 时,我发现进入并调整该映射很烦人。

在我的业务逻辑项目中使用 AutoMapper 是好主意还是坏主意?为什么?

I currently have a POCO class in my ASP.NET MVC project that handles all business logic. There are no references to other projects or third-party assemblies.

I am also using AutoMapper in my other projects to facilitate mapping between view models / entities. It is a fantastic tool and saves me considerable time when I make changes to fields on a given entity.

However, within my POCO class are a few segments of code that map between entities. The business purpose is to take entities from one data source and update another data source. Here I am manually mapping and I'm finding it annoying to go in and adjust that mapping when I could employ AutoMapper instead.

Is it a good idea or a bad idea to use AutoMapper in my business logic project? Why?

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

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

发布评论

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

评论(1

天生の放荡 2024-10-07 14:50:16

我会用一个问题来回答你的问题。

为什么使用 AutoMapper 映射属性会很糟糕?除了担心获取外部程序集引用之外,我想不出您不想使用 AutoMapper 的原因。

'll respond to your question with a question.

Why would it ever be bad to use AutoMapper to map properties? I cannot think of a reason, besides a concern over taking an external assembly reference, that you would not want to use AutoMapper.

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