使用 nHibernate 作为多个源的 ORM?

发布于 2024-12-11 00:48:03 字数 637 浏览 5 评论 0原文

我一直在许多 Web<->db 应用程序上使用 Fluent nHibernate,并取得了成功,并且非常喜欢它。仅使用数据库作为源非常简单,唯一的挑战是定义域模型、创建约定、映射等。

但是现在我面临着不同的方法,并且在考虑使用 nHibernate 之前需要一些输入。

现在,持久层中有三个或更多不同的数据源,有时您会写入/读取其中一个数据源,有时会写入/读取所有数据源。我认为工作单元模式可以很好地解决这个问题。

  • 0..1 数据库
  • 0..* 文件系统上的文件
  • 0..* 硬件

因此,会有来自不同来源的实体,其中一些是手动创建的,另一些是从数据库映射的。

关于如何处理这种情况,有什么好的想法吗?将存储库与 nHibernate 一起使用,针对不同的来源是否仍然有意义?

我自己的想法:

将 db/nhib 部分与其他源分开,并在其上构建一个存储库或外观(以暴露给 BL)。这知道如何与不同的来源合作。可能需要创建实体的新定义,因为它们可能包含来自不同来源的数据并呈现为“一个”。这样我仍然可以使用 nHib 进行数据库访问,并为其他部分编写一些其他 DAL 代码,并对 BL 隐藏实现。

这有意义吗?或者可以使用 nHib 以更好的方式解决这个问题吗?

I've been using Fluent nHibernate with success on many web<->db applications and like it a lot. Using only a database as a source is pretty straightforward with only challenges in defining your domain model, create conventions, mappings etc.

Now however I face a different approach and would like some input before concidering using nHibernate.

Now there is three or more different datasources in the persistence layer and sometimes you will write/read to one of them or sometimes to all of them. I suppose a unit of work pattern is good to solve this.

  • 0..1 Database
  • 0..* files on the file system
  • 0..* hardware

And so there would be entities coming from different sources, some of them created manually, other mapped from the DB.

Any good ideas of how to approach this scenario, and would it still make sense to use repositories with nHibernate, working towards different sources?

My own thoughts:

Separate the db/nhib part with the other sources and build a repository or facade upon that (to expose to BL). This knows how to work with the different sources. Probably need to create a new definition of entities as they might contain data from different sources and presented as "one". This way I could still use nHib for the db access and write some other DAL code for the other parts and hide the implementation from the BL.

Would that make sense, or could it be solved in a better way using nHib?

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

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

发布评论

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

评论(1

弥繁 2024-12-18 00:48:03

不同的实体有不同的来源

像 Repositories、UnitOfWorkClass 或实现 ISession 的自定义 SessionWrapper 这样的外观就足够了。棘手的部分是文件等源上的事务

当实体具有来自不同源的某些属性时,

我将使用 IUserTypes 像这里

实体是来自不同来源的混合

我将引入带有保存状态的内部对象的包装类对于每个数据源可能具有相应的工作单元对象

Different Entities have different sources

a facade like Repositories, UnitOfWorkClass or a custom SessionWrapper implementing ISession would be enough. the tricky part would be transactions on sources like files

When Entities have some properties from different sources

i would use IUserTypes like here

Entities are mixed from different sources

i would introduce Wrapperclasses with inner objects holding the state for each datasource maybe with the corresponding unitofwork-object

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