none
Linq to Sql.ToString() - part 2 RRS feed

Answers

  • Hi John,

    The GetCommand method needs a parameter of type IQueryable, but myQuery is a value of type double. While Enumerable.Average(Of TSource) Method (IEnumerable(Of TSource), Func(Of TSource, Decimal)) is acting on a sequence of values that are used to calculate an average, it does not belong to the scope of Linq to Sql, so you can not get the execution command information for this. You can get the command information for the query like:

    var myQuery = from c in Customers where c.ID > 5 select c;
    var cmd = myContext.GetCommand(myQuery);

    If you want to know how Average works, you can get it throough Reflector.

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, May 17, 2010 4:13 AM
    Moderator
  • Hi John,

    For getting the generated SQL in such situations, you can look into other methods like:

     

    Regards,


    Syed Mehroz Alam
    My Blog | My Articles
    Monday, May 17, 2010 7:02 AM

All replies

  • Hi John,

    The GetCommand method needs a parameter of type IQueryable, but myQuery is a value of type double. While Enumerable.Average(Of TSource) Method (IEnumerable(Of TSource), Func(Of TSource, Decimal)) is acting on a sequence of values that are used to calculate an average, it does not belong to the scope of Linq to Sql, so you can not get the execution command information for this. You can get the command information for the query like:

    var myQuery = from c in Customers where c.ID > 5 select c;
    var cmd = myContext.GetCommand(myQuery);

    If you want to know how Average works, you can get it throough Reflector.

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, May 17, 2010 4:13 AM
    Moderator
  • Hi John,

    For getting the generated SQL in such situations, you can look into other methods like:

     

    Regards,


    Syed Mehroz Alam
    My Blog | My Articles
    Monday, May 17, 2010 7:02 AM
  • Thanks Gents. Much appreciated - as always.
    Friday, May 21, 2010 5:28 PM