开发者

NHibernate -- How to fake one side of a many-to-many normalization

I have the following two tables:

Package
id

ClientPackage
id
clientNumber
packageId

The thing is that I do not have a Client table in this database (it resides in another database). Is there a way that I can create a Client mapping to a Client model which just consist of distinct "clientNumber" from the ClientPackage table while treating ClientPackage as a association table -- meaning that I do not want a class or mapping for ClientPackage. I'm thinking that I could 开发者_StackOverflowuse a component and an idbag to accomplish this but I just wanted a more experienced opinion so that I know I'm doing the right thing.


From NH's perspective, this is not a many-to-many relationship, precisely because Client is not mapped.

The mapping depends on how you want it represented in the domain model.

An idbag would work fine for mapping Package.Clients as an ICollection<int>. You don't need a component:

<idbag name="Clients" table="ClientPackage">
  <collection-id column="id" type="...">
    <generator class="..."/>
  </collection-id>
  <key column="packageId"/>
  <element column="clientNumber"/>
</idbag>

And then you'll use those ids to get the clients in the other database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜