Hi There,
I have a few tables with a composite ID:
Table: ProductsInBar
BarID (PK)
ProductID (PK)
...other columns...
Table: ProductsToGroups
ProductID (PK)
GroupID (PK)
StartDate, etc
What I need to do is add a relationship between ProductsInBar and
ProductsToGroups.
It looks to me like the relationship between ProductsInBar and
ProductsToGroups should be ManyToMany. (A bar has many products. Each
product can appear in multiple groups). I tried to add this
relationship to ProductsInBar as follows:
[Serializable]
[Class(Table = "ProductsInBar", Lazy = true, NameType =
typeof(ProductsInBar))]
public class ProductsInBar
{
//Composite primary key
[CompositeId]
[KeyProperty(1, Name = "BarID", Column = "BarID")]
[KeyProperty(2, Name = "ProductID", Column = "ProductID")]
public virtual long BarID { get; set; }
public virtual long ProductID { get; set; }
[Bag(0, Cascade = "all-delete-orphan", Lazy =
CollectionLazy.True, Table = "ProductsToGroups", Fetch =
CollectionFetchMode.Subselect)]
[Key(1, Column = "ProductID")]
[ManyToMany(2, ClassType = typeof(ProductsToGroups), Column =
"ProductID")]
public virtual IList<ProductsToGroups> ProductsToGroups { get;
set; }
}
The ProductsToGroups class looks like this:
[Serializable]
[Class(Table = "ProductsToGroups", Lazy = true, NameType =
typeof(ProductsToGroups))]
public class ProductsToGroups
{
[CompositeId]
[KeyProperty(1,Name="ProductID", Column="ProductID")]
[KeyProperty(1, Name = "GroupID", Column = "GroupID")]
public virtual long ProductID { get; set; }
public virtual long GroupID { get; set; }
[Property(Column = "STARTDATE")]
public virtual DateTime StartDate { get; set; }
//Other columns...
}
The ManyToMany mapping generates an error:
"collection foreign key mapping has wrong number of columns:
OnboardDashboardDomain.Domain.ProductsInBar.ProductGroups type:
component[BarID,ProductID]"
I'm probably going about this in the wrong way and would appreciate
any help you can give. For better or worse I've chosen to use
NHibernate.Mapping.Attributes throughout the domain, rather than XML
mappings, so a solution using annotations would be helpful (although
I'll settle for anything that works).
Thanks,
Huw
--
You received this message because you are subscribed to the Google Groups
"NHibernate Contrib - Development Group" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhcdevs?hl=en.