none
TSQL Modulo Operator support in Linq to Entities RRS feed

  • Question

  • Hi

    Quick question: does anyone know if Linq to Entities supports the Modulo operator (Mod in vb; % in c#). In other words is it able to understand and output the t-sql equivalent when using a SQL Server 2012 database?


    Tuesday, October 15, 2013 8:35 AM

Answers

  • Hello,

    >>does anyone know if Linq to Entities supports the Modulo operator (Mod in vb; % in c#).

    I think it is yes.

    In C#:

    using (DataBaseFirstDBEntities db = new DataBaseFirstDBEntities())
    
                {
    
                    var result = (from o in db.Orders
    
                                  where (o.OrderID % 2) == 0
    
                                  select o).ToList();
    
                }
    

    In VB:

    Dim db As LinqDBEntities = New LinqDBEntities()
    
    
            Dim result = (From o In db.Orders
    
                          Where (o.OrderID Mod 2) = 0
    
                         Select o).ToList()
    

    If I misunderstood you, please let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, October 16, 2013 3:05 AM
    Moderator