0

我在 ASP.NET MVC3 项目中使用 Fluent NHibernate。我正在编写一个自定义会员提供程序并设置了一个 FNHRoleProvider 类。其中一部分包含以下 try catch 块:

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 语句中。我还可以在对象浏览器中查看命名空间的这一部分。

如何解决构建错误?

4

1 回答 1

1

我怀疑您也将命名空间命名为 NHibernate,因此最好NHibernate.Criterion.先删除Restrictions

于 2012-08-14T08:38:01.360 回答