我在一个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;
}尽管我已经在using语句中添加了NHibernate.Criterion,但我收到了一个错误,指出Criterion在当前名称空间中不存在。我还可以在对象浏览器中查看命名空间的这一部分。
如何解决构建错误?
发布于 2012-08-14 16:38:01
我怀疑您也将命名空间命名为NHibernate,因此最好在删除Restrictions之前删除NHibernate.Criterion.
https://stackoverflow.com/questions/11940892
复制相似问题