Extend a mapping containing a composite key, and define a HasMany - doesn't work
I have the following scenario:
- entity UserRole (UserRoleIdentifier - composite key described below, User, Role)
- entity AppUserRole - extends the UserRole class
- entity AppUserRole - one to many - UserRoleAdministrativeUnit
UserRoleIdentifier public virtual int UserId { get; set; } public virtual int RoleId { get; set; }
The following code defines the one-to-many relation.
[Serializable] public class AppUserRole : UserRole { public virtual IList<UserRoleAdmUnit> UserRoleAdministrativeUnits { get; set; } }
public class AppUserRoleMap : SubclassMap<AppUserRole
{
public AppUserRoleMap()
{
HasMany(u => u.UserRoleAdministrativeUnits).KeyColumns.Add("UserId", "RoleId").Cascade.Delete().Inverse();
}
}
There is an crash on this configuration when Fluent initializes: collection foreign key mapping has wrong number of columns: Business.Model.UsersManagement.AppUserRole.UserRoleAdministrativeUnits type: component[UserId,RoleId]
Stack Trace: [MappingException: collection foreign key mapping has wrong number of columns: Business.Model.UsersManagement.AppUserRole.UserRoleAdministrativeUnits type: component[UserId,RoleId]] NHibernate.Mapping.Collection.Validate(IMapping mapping) +390 NHibernate.Cfg.Configuration.ValidateCollections() +121 NHibernate.Cfg.Configuration.Validate() +38 NHibernate.Cfg.Configuration.BuildSessionFactory() +74 FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() +73
[FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
- Database was not configured through Database method. ] FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() +117 Common.Library.NHibernate.Data.HibernateManager.Initialize() in d:\Projects\Infobest.Library\src\Projects\Components\Common.Library.NHibernate.Data\HibernateManager.cs:125 Web.MvcApplication.Application_Start() in d:\Projects\3R\Development\RALInterfaceEditor\Web\Global.asax.cs:52
I see. Can you post full code of your example please (entities, mapping, conventions, configuration, helpers, etc)? If it's not a OSS project, you can email me (email address from my github profile)
Any news?
Err, not yet. I'll try to carve out some time this week.
+1