简体   繁体   English

nhibernate 3不支持指定的方法

[英]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. 我最近从nhibernate 2迁移到3,我遇到的问题是,在我现在遇到问题之前的大部分查询中。 and i see this error Specified method is not supported although they all work well in hibernate 2 . 我看到这个错误虽然它们在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 = EducationDegreeSearch.Split(' ');
            foreach (string search in searchs)
            {
                if (!String.IsNullOrEmpty(search))
                {
                    AddExpression(p => p.Title.Contains(search));
                }
            }
        }
        return this;
    }

}

You need to select before Take. 你需要在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);

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." 如果p.Title为null,那么你将得到“不支持特定方法”。 You could try writing 你可以尝试写作

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

or using C# 6 或使用C#6

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

I just have similar problem, and it happen because property, which was mapped as "many-to-one" have attribute lazy="no-proxy". 我只是遇到类似的问题,因为属性被映射为“多对一”,属性为lazy =“no-proxy”。 I removed that, and it works. 我删除了它,它的工作原理。 Problem is probably because this property was used in where part of query. 问题可能是因为这个属性是在查询的WHERE部分使用。 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". 因此,PropertyType类型的属性不应该具有lazy =“no-proxy”。 I have tried to implicitly fetch Property, but it doesn't work. 我试图隐式获取属性,但它不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM