Question

I have a class which implements the following interface:

IUser {
    string UserName { get; set; }
}

The default class which implements this interface (User) and the interface are defined within the core library and ideally i do not wish to modify this. However i need to add an additional property to my user therefore i have added a custom class which also implements the IUser interface. I have mapped this the same as i mapped the User class but with the additional fields. However if i try to say:

session.Get<IUser>(1);

It throws the error:

Ambiguous persister for Security.IUser implemented by more than one hierarchy: Web.Security.Models.User Security.Models.User

I can appreciate why i get this as NHibernate has no way to tell which is my preferred type to use. I was wondering if it was possible to prompt NHibernate this in the mapping?

I'd appreciate the help. Thanks

Was it helpful?

Solution

NHibernate has the notion of entity name

// in UserMap
EntityName("user");

// in SpecialUserMap
EntityName("specialUser");

// then in Query
(IUser)session.Get("user", 1);
// or
(IUser)session.Get("specialUser", 1);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top