映射实现相同接口的多个类
我有一个实现以下接口的类:
IUser {
string UserName { get; set; }
}
实现此接口的默认类(用户)和该接口是在核心库中定义的,理想情况下我不希望修改它。但是,我需要向我的用户添加一个附加属性,因此我添加了一个自定义类,它也实现了 IUser 接口。我的映射与映射 User 类相同,但具有附加字段。但是,如果我尝试说:
session.Get<IUser>(1);
它会抛出错误:
由多个实施的 Security.IUser 的不明确持久化器 层次结构:Web.Security.Models.User 安全.模型.用户
我可以理解为什么我会得到这个,因为 NHibernate 无法判断我喜欢使用哪种类型。我想知道是否可以在映射中提示 NHibernate 这个?
我将不胜感激的帮助。谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NHibernate 有实体名称的概念
NHibernate has the notion of entity name