[英]Specified method is not supported nhibernate 3
我最近從nhibernate 2遷移到3,我遇到的問題是,在我現在遇到問題之前的大部分查詢中。 我看到這個錯誤雖然它們在hibernate 2中運行良好,但不支持指定的方法。 這些查詢中的一個是這樣的
public JsonResult AllEducationDegree(string search)
{
var data = Repository<EducationDegree>
.FindBySpecification(new EducationDegreeSpecification().Search(search))
.Take(10)
.Select(p => new NameValue(p.Title, (int)p.Id))
.ToList();
// .AsDropdown(" ");
return Json(data, JsonRequestBehavior.AllowGet);
}
public class EducationDegreeSpecification : FluentSpecification<EducationDegree>
{
public EducationDegreeSpecification Search(string EducationDegreeSearch)
{
if (!String.IsNullOrEmpty(EducationDegreeSearch))
{
string[] searchs = EducationDegreeSearch.Split(' ');
foreach (string search in searchs)
{
if (!String.IsNullOrEmpty(search))
{
AddExpression(p => p.Title.Contains(search));
}
}
}
return this;
}
}
你需要在Take之前選擇。 它應該工作。
var data = Repository<EducationDegree>
.FindBySpecification(new EducationDegreeSpecification().Search(search))
.Select(p => new NameValue(p.Title, (int)p.Id))
.Take(10)
.ToList();
// .AsDropdown(" ");
return Json(data, JsonRequestBehavior.AllowGet);
在最后幾行......
AddExpression(p => p.Title.Contains(search));
如果p.Title為null,那么你將得到“不支持特定方法”。 你可以嘗試寫作
AddExpression(p => p.Title != null && p.Title.Contains(search));
或使用C#6
AddExpression(p => p.Title?.Contains(search));
我只是遇到類似的問題,因為屬性被映射為“多對一”,屬性為lazy =“no-proxy”。 我刪除了它,它的工作原理。 問題可能是因為這個屬性是在查詢的WHERE部分使用。 喜歡:
EntityType aliasEntityType = null;
PropertyType aliasPropertyType = null;
QueryOver.Of<EntityType>(() => aliasEntityType)
.JoinAlias(() => aliasEntityType.Property, () => aliasPropertyType)
.Where(() => aliasPropertyType.SomeValue == someValue)
....
因此,PropertyType類型的屬性不應該具有lazy =“no-proxy”。 我試圖隱式獲取屬性,但它不起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.