Topic
4 replies Latest Post - ‏2012-08-17T17:39:29Z by rsouto
rsouto
rsouto
8 Posts
ACCEPTED ANSWER

Pinned topic Canonical Functions for Entity Framework

‏2012-08-10T14:00:51Z |
The documentation states that there is support for them.
http://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.swg.im.dbclient.adonet.doc%2Fdoc%2Fc0054118.html

I have found store-specific functions at the IBM.Data.DB2.Entity.DB2Functions class, but the other functions (Average, Count, etc), I do not see how to call them inside a LINQ expression.

Could someone help?

Thank you,
Ricardo
Updated on 2012-08-17T17:39:29Z at 2012-08-17T17:39:29Z by rsouto
  • SystemAdmin
    SystemAdmin
    2826 Posts
    ACCEPTED ANSWER

    Re: Canonical Functions for Entity Framework

    ‏2012-08-13T19:03:37Z  in response to rsouto
    Hi Ricardo,

    LINQ to Entities queries use methods that expose Canonical Functions in EntityFunctions class (System.Data.Objects namespace) as follows:
    ...
    using (SampleDBEntities sampleEntities = new SampleDBEntities())
    {
    var products = from p in sampleEntities.PRODUCTs
    where EntityFunctions.DiffDays(p.PROMOEND, p.PROMOSTART) < 30
    select p;
    foreach (PRODUCT p in products)
    {
    Console.WriteLine(p.PID);
    }
    }
    ...

    Thanks and regards,
    Devendra
    • rsouto
      rsouto
      8 Posts
      ACCEPTED ANSWER

      Re: Canonical Functions for Entity Framework

      ‏2012-08-13T22:13:15Z  in response to SystemAdmin
      Hi Devendra.

      Thank you for the reply. That particular function is not supported on Informix database, so we could not test it.

      However, EntityFunctions class does not contain the other canonical functions like Year, Month, Day, Sum, Average, etc.

      Any idea how to call these particular functions?

      We have tested 2 sets of drivers so far with Informix:
      • 9.7 Fix Pack 6
      • 10.1 GA

      Glad if you could help.

      Thanks!
  • SystemAdmin
    SystemAdmin
    2826 Posts
    ACCEPTED ANSWER

    Re: Canonical Functions for Entity Framework

    ‏2012-08-17T06:55:20Z  in response to rsouto
    Hi Ricardo,
    Some functions are directly available via CLR methods (mapped to Data source through canonical functions).

    Example 1:
    using (stores7Entities ctxtObj = new stores7Entities())
    {
    var orders = from o in ctxtObj.orders
    where o.ship_date.HasValue == true && o.ship_date.Value.Year > 2005
    //where ((DateTime)(o.ship_date)).Year > 2005 // May use explicit cast
    select o;

    foreach (order o in orders)
    {
    Console.WriteLine(o.customer_num);
    }
    }
    Example 2:
    using (stores7Entities ctxtObj = new stores7Entities())
    {
    var query = ctxtObj.orders.Select(o => o.ship_weight).Average();
    Console.WriteLine(query);
    }

    Thanks and regards,
    Devendra
    • rsouto
      rsouto
      8 Posts
      ACCEPTED ANSWER

      Re: Canonical Functions for Entity Framework

      ‏2012-08-17T17:39:29Z  in response to SystemAdmin
      That is exactly what we needed. Thank you!