Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate.LINQ Supported Operators

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 life of me I can't seem to find a page that explains what's supported and unsupported in this implementation. For example, can I use Skip & Take? What can I not use?

like image 296
roufamatic Avatar asked Sep 23 '10 17:09

roufamatic


1 Answers

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<Catalog>()
            .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.

like image 107
rebelliard Avatar answered Oct 12 '22 13:10

rebelliard