Fluent NHibernate Mapping for DDD Model

ぃ、小莉子 提交于 2020-01-05 05:59:07

问题


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
}

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.

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

Any help would be appreciated?

Thanks in advance.


回答1:


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.

I see two options. 1, the class A has a indirect relationship to Location through a LocationRepository where you can GetLocationByA(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");
                          });
    }
}


来源:https://stackoverflow.com/questions/5906163/fluent-nhibernate-mapping-for-ddd-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!