Specified method is not supported nhibernate 3
i recently migrated from nhibernate 2 to 3, the problem i have is , in most of query i had before i have a problem right now. and i see this error Specified method is not supported although they all work well in hibernate 2 . one on these query is like this
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 = EducationDe开发者_Go百科greeSearch.Split(' ');
foreach (string search in searchs)
{
if (!String.IsNullOrEmpty(search))
{
AddExpression(p => p.Title.Contains(search));
}
}
}
return this;
}
}
You need to select before Take. It should work.
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);
I just have similar problem, and it happen because property, which was mapped as "many-to-one" have attribute lazy="no-proxy". I removed that, and it works. Problem is probably because this property was used in where part of query. Like:
EntityType aliasEntityType = null;
PropertyType aliasPropertyType = null;
QueryOver.Of<EntityType>(() => aliasEntityType)
.JoinAlias(() => aliasEntityType.Property, () => aliasPropertyType)
.Where(() => aliasPropertyType.SomeValue == someValue)
....
So, Property of type PropertyType shouldn't have lazy="no-proxy". I have tried to implicitly fetch Property, but it doesn't work.
In the last few lines...
AddExpression(p => p.Title.Contains(search));
if p.Title is null, then you'd get "specific method is not supported." You could try writing
AddExpression(p => p.Title != null && p.Title.Contains(search));
or using C# 6
AddExpression(p => p.Title?.Contains(search));
精彩评论