ADO.NET EF 作为 DAL

发布于 2024-09-15 11:32:55 字数 584 浏览 0 评论 0原文

我正在开发一个使用分层架构的项目。我有一个 DAL,其中使用实体框架、一个使用 DAL 返回的对象的业务逻辑层和一个应用程序层。

我不确定我的想法是否正确,所以我只想问你的想法。

我的 DAL 基于映射器。我有 BLL 用于操作我的数据的类型(映射器)。这些映射器返回 DTO,因为我不想向 BLL 公开任何 EF 对象,因此它们的实现不依赖于 EF 来工作。

所有这些映射器所做的都是对单个“表”进行 CRUD 操作,例如:

using (var contex = new EFEntities()){
  var obj = (from x in context.Table where x.ID == param select x).SingleOrDefault;
  return Map(x.ToList());
}

Map 方法将 EF 对象映射到 DTO,该 DTO 仅具有一些属性来映射我想要公开的值。

有更优雅的方法吗?我只是使用 EF 来方便访问我的数据库 - 我不必编写任何 ADO.NET 代码。

欢迎对此提出任何意见。

谢谢。

I'm developing a project using a layered architecture. I have a DAL in which i'm using Entity Framework, a business logic layer which consumes the objects returned by the DAL and an app layer.

I'm not entirely sure i'm thinking this right, so i'll just ask you what you think.

My DAL is based on mappers. I have types - mappers - that the BLL uses to operate on my data. These mappers return DTO's, because i did not want to expose to my BLL any EF objects so their implementations are not dependent on EF to work.

All these mappers do are CRUD actions on a single 'table', like:

using (var contex = new EFEntities()){
  var obj = (from x in context.Table where x.ID == param select x).SingleOrDefault;
  return Map(x.ToList());
}

The Map method maps the EF object to a DTO, which has only some properties to map the values i want to expose.

Is there a more elegant approach to this? I am just using EF to facilitate the access to my database - i don't have to write any ADO.NET code.

Any input on this would be welcome.

Thanks.

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

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

发布评论

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

评论(1

你又不是我 2024-09-22 11:32:57

我有一个正在使用的 DAL
实体框架,业务逻辑
消耗对象的层
由 DAL 和应用层返回。

这是一种歪曲,因为您将完整的对象层放入 DAL 中。 EF 不仅仅是 DAL。

消费的业务逻辑层
DAL 返回的对象和
应用层。

您可能想要查找的术语是“贫血对象模型”,这不是一个好术语。

有没有更优雅的方法
这个?

别跟EF斗了如果你不喜欢它,就不要使用它——周围有很多更好的框架。

I have a DAL in which i'm using
Entity Framework, a business logic
layer which consumes the objects
returned by the DAL and an app layer.

That is a perversion, given that you are putting a complete object layer into your DAL. EF is a lot more than a DAL.

a business logic layer which consumes
the objects returned by the DAL and an
app layer.

The term you may want to look up for that is "anemic object model", and it is not a nice term.

Is there a more elegant approach to
this?

Don't fight EF. if you dont like it, don't use it - there are a LOT better frameworks around.

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