我在ASP.NET MVC3项目中使用Fluent NHibernate。我正在编写自定义成员资格提供程序并设置了FNHRoleProvider类。其中一部分包含以下try catch blocK:
private Entities.Roles GetRole(string rolename)
{
Entities.Roles role = null;
using (ISession session = SessionFactory.OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
try
{
role = session.CreateCriteria(typeof(Entities.Roles))
.Add(NHibernate.Criterion.Restrictions.Eq("RoleName", rolename))
.Add(NHibernate.Criterion.Restrictions.Eq("ApplicationName", this.ApplicationName))
.UniqueResult<Entities.Roles>();
//just to lazy init the collection, otherwise get the error
//NHibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
IList<Entities.Users> us = role.UsersInRole;
}
catch (Exception e)
{
if (WriteExceptionsToEventLog)
WriteToEventLog(e, "GetRole");
else
throw e;
}
}
}
return role;
}
我收到一条错误,指出当前命名空间中不存在Criterion,尽管事实上我已经将NHibernate.Criterion添加到了我的using语句中。我还能够在对象浏览器中查看命名空间的这一部分。
如何解决构建错误?
答案 0 :(得分:1)
我怀疑您将命名空间命名为NHibernate,因此最好在NHibernate.Criterion.
之前移除Restrictions