Ask a questionAsk a question
 

Answerv1.5 CTP (Not CTP2) and Count....Where or Where.....Count

  • Thursday, September 24, 2009 1:45 PMDave Russell Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I'm developing with the original CTP1.5 release and I came across this today.  Is it fixed in CTP2 ?

    I want a query:

    http://mylocalservice/DataService/Service.svc/MyTable()/$count?$filter=IsPublished eq false

    So I started with....

            Dim c = ctx.MyTable.Count( _
                    Function(a As MyRec) (a.IsPublished = False))

    but I got a "Not Supported" error.

    However.....

            Dim c = ctx.MyTable.Where(Function(a As MyRec) (a.IsPublished = False)).Count()

    works just fine.

    "Select Count...Where" seemed more logical to me than "Select Where....Count" - and Select Count Where is what appears in the url too.

Answers

  • Monday, September 28, 2009 6:33 PMPeter Qian - MSFTAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    This is by-design. We do not (yet) support predicates in the LINQ direct execution methods, including:

    First
    FirstOrDefault
    Single
    SingleOrDefault
    Count
    LongCount

    .Where(predicate).Count() is the correct way to go (for now). There is not yet a plan to support the predicate expressions inside the above methods.

    Regards,
    PQ

    Peter Q. http://blogs.msdn.com/peter_qian

All Replies

  • Monday, September 28, 2009 6:33 PMPeter Qian - MSFTAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    This is by-design. We do not (yet) support predicates in the LINQ direct execution methods, including:

    First
    FirstOrDefault
    Single
    SingleOrDefault
    Count
    LongCount

    .Where(predicate).Count() is the correct way to go (for now). There is not yet a plan to support the predicate expressions inside the above methods.

    Regards,
    PQ

    Peter Q. http://blogs.msdn.com/peter_qian