开发者

Creating a Virtual Many-To-Many Relationship with NHibernate

Let's say you have three entities - Categories, Sites and Items. The Items table has a CategoryID and a SiteID. If I want to find the sites for a given category, I can get that with a mapping in NHibernate that looks something like:

public CategoryMap()
{
  //..
  ManyToMany(x => x.Site)
    .Table("Items")
    .ParentKey("CategoryID")
    .ChildKey("SiteID");
}

This works great if I want a list of all of the categories, and the sites the category belongs to. But I also want to create a category called "Uncategorized" and list the Sites which don't belong to a Category in there. I could do it with a second query, but I was wondering if there was开发者_如何学Go a way to create a "virtual" Category that would be part of the Category collection, or some other trick to this I'm missing. I'm also open to being told that this is highly wrong.


That would be part of your Model / Service; NHibernate can't provide it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜