NHibernate - 如何解决 nhibernate 缓存的转换问题?
我所拥有的是 User 类,并且还有 2 个子类 vipUser 和 RegularUser。 在登录页面中,我想检查身份验证,但我不知道它是 vipUser 还是常规用户。如果是 vip,则重定向到一个位置,如果是常规到另一个位置。 身份验证方法必须在 User 类上才能实现某些目的 - 像这样:
Function Authenticate(ByVal username As String, ByVal password As String) As User Implements IMindriUserDao.Authenticate
Return MyBase.GetUniqueByCriteria(Restrictions.Where(Of User)(Function(x) x.Username = username AndAlso x.Password = password))
End Function
问题是,在我从 nhibernate 获得用户身份验证后,我想检查他是 vip 还是普通用户,但用户已经在缓存中了没有强制转换选项的用户来检查用户是什么类型... 有什么建议吗?
希望我说得足够清楚..
谢谢!
What i have is User class and say there are 2 more sub classes vipUser and regularUser.
in the login page i wanna check authentication and i don't know if it is vipUser or regularUser.. if it's vip the redirect is to one location and if it's regular to another location.
the authentication method must be on the User class for some resone - like this:
Function Authenticate(ByVal username As String, ByVal password As String) As User Implements IMindriUserDao.Authenticate
Return MyBase.GetUniqueByCriteria(Restrictions.Where(Of User)(Function(x) x.Username = username AndAlso x.Password = password))
End Function
the issue is that after i get from the nhibernate the authentication with the User now i wanna check if he is vip or regular but the user is already in the cache as a User without a casting option to check what type the User is...
any suggestions?!
Hope i was clear enough..
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
2 个选项:多态性 或 任意映射
多态性(抱歉,我是 C#,但我对 VB.NET 不太熟练)
任意映射:任何对 User
public 有延迟加载引用的地方实体映射()
{
ReferencesAny(x => x.User)
}
2 options: polymorphism or any-mapping
Polymorphism (sorry for being c# but im not fluent in VB.NET)
Any-Mapping: everywhere where you have lazyloaded reference to User
public EntityMap()
{
ReferencesAny(x => x.User)
}
你确定吗?用户对象应该是正确的具体类型,并且您应该能够使用
is
或as
运算符进行检查。也就是说,使用子类化的角色属性(即 User.UserType)要容易得多。
Are you sure? The user object should be the correct concrete type and you should be able to use the
is
oras
operators to check.That said, it's much easier to work with role properties that subclassing, i.e. User.UserType.