The specified method is not supported by nhibernate 3

I recently switched from nhibernate from 2 to 3, I have a problem in most of the queries that I had before I had the problem right now. and I see this error The specified method is not supported although they all work well in sleep mode 2. one of these requests is similar to 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 = EducationDegreeSearch.Split(' ');
            foreach (string search in searchs)
            {
                if (!String.IsNullOrEmpty(search))
                {
                    AddExpression(p => p.Title.Contains(search));
                }
            }
        }
        return this;
    }

}
+3
source share
3 answers

You need to choose 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);
+3
source

, , , "--", lazy = "no-proxy". , . , , , . :

 EntityType aliasEntityType = null;
 PropertyType aliasPropertyType = null; 

 QueryOver.Of<EntityType>(() => aliasEntityType)
 .JoinAlias(() => aliasEntityType.Property, () => aliasPropertyType)
 .Where(() => aliasPropertyType.SomeValue == someValue)
 ....

, PropertyType lazy = "no-proxy". , .

0

In the last few lines ...

AddExpression(p => p.Title.Contains(search));

if p.Title is null, then you will get "a specific method is not supported." You can try to write

AddExpression(p => p.Title != null && p.Title.Contains(search));

or using c # 6

AddExpression(p => p.Title?.Contains(search));
0
source

Source: https://habr.com/ru/post/1782590/


All Articles