Skip to content

Extend a mapping containing a composite key, and define a HasMany - doesn't work #251

@Cristina-Alboni

Description

@Cristina-Alboni

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions