views:

126

answers:

1

I have a many to many relationship between entities and there is a table view acting as a lookup table defining the relationship.

I'm curious how to map to a view as opposed to a table within a database.

ie, Table mapping:

public SomeMap()
{
    Id(...)//set Id and other mapped properties
    HasManyToMany(x => x.Items)
     .Table("SomeLookupTable")
     .ParentKeyColumn("ParentID")
     .ChildKeyColumn("ChildID")
     .LazyLoad()
     .Inverse()
     .Cascade.SaveUpdate();
}

UPDATE

I just stumbled across something in the FluentNHibernate Google Group area regarding this. In my test case I only use one self-referencing lookup, although in practice there is two. The issue is explained in detail here.

+1  A: 

Have you tried mapping to the view as if it was a table? I don't see any reason why this wouldn't work.

Jon Seigel
Maybe just add .ReadOnly() and drop Cascase declaration, unless view is updatable
veggerby
I have actually and this seems to work in a test case. My mapping is identical to what's above, however I'm presented with a "Can't figure out what the other side of a many-to-many should be." Strange, in the test case it does indeed map to the view with no issues.
Alexis Abril
Marked this as the answer due to the original question. Views are accessible just like tables, I had bumped into another issue entirely which was masking this(update above).
Alexis Abril