0
我在ASP.NET MVC3項目中使用Fluent NHibernate。我正在編寫一個自定義成員資格提供程序,並設置了FNHRoleProvider類。它的部分包括以下try catch塊:使用NHibernate.Criterion.Restriction時未找到名稱空間
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;
}
我收到一個錯誤,指出標準不存在於當前的命名空間,儘管我已經添加NHibernate.Criterion我使用聲明的事實。我也可以在對象瀏覽器中查看這部分命名空間。
如何解決構建錯誤?
'拋e卸下
NHibernate.Criterion.
;'應該是'拋;'othwise你失去堆棧跟蹤 – Firo 2012-08-14 08:35:06'的IList我們=作用。在'UniqueResult'之前用'UsersInRole;'會更好地替換爲'.SetFetchMode(「UsersInRole」,FetchMode.Eager) –
Firo
2012-08-14 08:36:43