流利的NHibernate映射为DDD模式 [英] Fluent NHibernate Mapping for DDD Model

查看:218
本文介绍了流利的NHibernate映射为DDD模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图寻找解决方案,以我目前具有映射使用功能NHibernate我DDD模式的问题。如果有人可以只把我在正确的方向,这将是AP preciated。

I have been trying to look for solutions to the problem that I am currently having with mapping my DDD model using Fluent NHibernate. If someone can just put me in the right direction that would be appreciated.

基本上我有这个类,我想图:

Basically I have this class that I would like to map:

public class A : EntityObject
{
    //assuming some other attributes have been mapped properly

    public virtual Location MyLocation { get; private set; }
}

public class Location : EntityObject
{
    public virtual string Name { get; private set; }
}

public Class AMap : ClassMap<A>
{
    //????  How to map the Location
}

从数据库中过氧化值,所以从表A没有直接的关系,以表位置。表A具有使用具有访问LocationId列然后可以我映射到位置表之前加入去通过表B和表C。

From database pov, there is no direct relationship from Table "A" to Table "Location". Table "A" has to go through Table "B" and Table "C" using join before having access to the LocationId column which can then me mapped to the Location table.

什么是在映射功能NHibernate的位置对象的最佳方式是什么?如果有任何不清楚,请让我知道。

What's the best way in mapping the Location object in Fluent NHibernate? If there is anything that is unclear, please let me know.

任何帮助将是AP preciated?

Any help would be appreciated?

在此先感谢。

推荐答案

好了没有约你的域名多的信息,我认为像UpTheCreek - 你可以模拟位置作为的ValueObject,扩展A级

Well not having that much info about your domain i think like UpTheCreek - that you may model Location as a ValueObject that extends Class A.

我看到两个选项。 1,A类具有通过LocationRepository一个间接的关系,位置在那里你可以GetLocationByA(A一)

I see two options. 1, the class A has a indirect relationship to Location through a LocationRepository where you can GetLocationByA(A a)

2,你的模型位置,为的ValueObject是A类的集合的一部分,并通过存储库加载。根据您的域模型和位置,之间的关系,地点是在飞行或A的构造对不起,下面的格式......

2, you model Location as a Valueobject that is part of class A's aggregate and is loaded through A's repository. Depending on you domain model and the relationship between Location and A, Location is loaded on the fly or during constructor of A. Sorry for the formatting below...

public class AMap : ClassMap<A>
{
    public AMap()
    {
Component(x => x.MyLocation, m =>
                          {
                              m.Map(x => x.Name, "Name");
                          });
    }
}

这篇关于流利的NHibernate映射为DDD模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆