Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Cristina-Alboni opened this issue Nov 18, 2013 · 4 comments

Comments

@Cristina-Alboni
Copy link

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
@chester89
Copy link
Collaborator

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)

@Cristina-Alboni
Copy link
Author

Any news?

@chester89
Copy link
Collaborator

chester89 commented Dec 2, 2013

Err, not yet. I'll try to carve out some time this week.

@futurechan

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants