Extending LINQ to Nhibernate provider, in combination with Dynamic LINQ problem

前端 未结 3 1978
春和景丽
春和景丽 2021-01-02 21:28

I\'m using NHibernate 3.1.0 and I\'m trying to extend the LINQ provider by using BaseHqlGeneratorForMethod and extending the DefaultLinqToHqlGeneratorsReg

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-02 22:32

    There are two, well defined, separate stages here:

    1. Converting the dynamic (string) query into a static expression (done by the Dynamic Linq library)
    2. Parsing that into an HqlTree, then executing (done by NHibernate)

    Since you have determined that a static expression works well, the problem lies in 1.

    What happens if you do the following?

    var results = Enumerable.Empty().AsQueryable();
    string pId = "1";
    results = results.Where("Id.ToString().Contains(@0)", pId);
    

    If it fails, you'll have confirmed it's a problem with Dynamic Linq alone (i.e. it doesn't support the expression you're feeding it), so you'll have to dig into it and patch it.

    Semi-related: the ToStringGenerator looks useful; could you submit a patch for NHibernate? http://jira.nhforge.org

提交回复
热议问题