Monday, October 31, 2011

Not all Linq provider approaches are the same

Whereas NHibernate Linq don't have a problem immediately reaching C#'s functions..

public JsonResult GetUpdated(Guid id)
{
    var js = new JsonResult();

    js.Data =
        new
        {
            Record = (from p in _person.All
                      where p.PersonId == id
                      select new { 
                          p.PersonId, 
                          p.Username, 
                          p.Firstname, 
                          p.Lastname, 
                          p.FavoriteNumber, 
                          p.Country,
                          RowVersion = CustomStringFunctionHere(p.RowVersion ?? new byte[] { })
                      } ).Single()
        };

    return js;
}

string CustomStringFunctionHere(byte[] a)
{
    return "AAA" + Convert.ToBase64String(a) + "BBB";
}

..Entity Framework does:

LINQ to Entities does not recognize the method 'System.String CustomStringFunctionHere(Byte[])' method, and this method cannot be translated into a store expression.


NHibernate do the projection differently, its select expression is not being translated to its store equivalent.

1 comment:

  1. Michael Buen

    It looks like Kellerman Software has a MySQL LINQ Provider:
    https://www.kellermansoftware.com/p-47-net-data-access-layer.aspx

    ReplyDelete