首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用NHibernate.Criterion.Restriction时找不到命名空间

使用NHibernate.Criterion.Restriction时找不到命名空间
EN

Stack Overflow用户
提问于 2012-08-14 03:22:56
回答 1查看 600关注 0票数 0

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

代码语言:javascript
复制
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在当前名称空间中不存在。我还可以在对象浏览器中查看命名空间的这一部分。

如何解决构建错误?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-14 16:38:01

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11940892

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档