NHibernate.LINQ Supported Operators

后端 未结 3 1150
陌清茗
陌清茗 2020-12-25 08:07

I\'m trying to evaluate NHibernate.LINQ 1.0 without actually writing any code. Ayende has admitted that this version of LINQ support is subpar compared to EF, but for the li

3条回答
  •  借酒劲吻你
    2020-12-25 08:27

    You can check LINQ for NHibernate examples to see tests done by Ayende himself on what's implemented and what's not for this provider.

    Some of those generally supported:

    • Anonymous type creation. new { Person = x.Name }
    • First(). query.First()
    • FirstOrDefault(). query.FirstOrDefault()
    • Single(). query.Single()
    • SingleOrDefault(). query.SingleOrDefault()
    • Aggregate(). query.Aggregate((x1,x2) => x1)
    • Contains(). query.Where(x => x.Name.Contains("Foo"))
    • StartsWith().
    • EndsWith().
    • Substring(). where db.Methods.Substring(e.FirstName, 1, 2) == "An"
    • Sub-queries. query.Where(x => x.Company.Id == 4)
    • Count(). query.Where(x => x.Relatives.Count > 0)
    • Any(). query.Any()
    • Take(). query.Take(10)
    • Skip(). query.Take(10).Skip(4)
    • OrderBy(). orderby x.Name descending
    • Replace(). AfterMethod = e.FirstName.Replace("An", "Zan"),
    • CharIndex(). where db.Methods.CharIndex(e.FirstName, 'A') == 1
    • IndexOf(). where e.FirstName.IndexOf("An") == 1

    Problematic:

    • Group by
    • Joins

    One of my own examples:

    query = NSession.Session.Linq()
                .Where(acc => acc.Company.Status == "A")
            .Where(acc => acc.Id.StartsWith("12-536"))
            .Where(acc => acc.Id.EndsWith("92") || acc.Id.EndsWith("67"))
            .Take(10).OrderBy(acc => acc.Title);
    

    If you're production application is using the latest stable build 2.1.2.4 like I am, you're stuck with what the NHibernate.Linq provider gives us until NHibernate 3.0 (trunk) gets a stable release and we feel safe enough to use it on major applications. Until then, I'm more than happy with a mixture of NHibernate.Linq and HQL.

提交回复
热议问题