0
votes

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 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.

1
This seems highly wrong to me. KISS. - cbp
Perhaps. But KISS in this case means I have to do two queries in NHibernate to get something I can do in one with SQL. I'd prefer not to do that. - Cory Foy

1 Answers

0
votes

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