New Posts New Posts RSS Feed: "Where" not showing in IntelliSense
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

"Where" not showing in IntelliSense

 Post Reply Post Reply
WardBell View Drop Down

Joined: 31-Mar-2009
Location: Emeryville, CA,
Posts: 338
Post Options Post Options   Quote WardBell Quote  Post ReplyReply Direct Link To This Post Topic: "Where" not showing in IntelliSense
    Posted: 23-Apr-2010 at 12:03am
A customer wrote:
"I tried to type the following line

_customersQuery = 
  _customersQuery.Where(c => c.CompanyName.ToUpper().StartsWith(searchTxt));
but the "Where" method does not show in IntelliSense and the code will not compile."
My first thought: he forgot to add "using IdeaBlade.EntityModel;" (thats "Imports IdeaBlade.EntityModel" in VB)
This omission is almost always the reason that DevForce LINQ extension methods don't appear. Happens to me all of the time.
Try commenting out this "using" statement on some working code and you'll see what I mean.
But that wasn't the cause of his problem as I quickly discovered when he sent me something like this:
using System;
using IdeaBlade.EntityModel;
namespace WhatIsWrong {
  public class CantFindWhere {
    IEntityQuery _customersQuery;
    public CantFindWhere(string searchTxt) {
      var mgr = new NorthwindIBEntities();
      _customersQuery = mgr.Customers;
      if (!String.IsNullOrEmpty(searchTxt)) {
        _customersQuery =
          _customersQuery.Where(c => c.CompanyName.ToUpper().StartsWith(searchTxt));
      // more ... but irrelevant
He intends to retrieve every customer ... unless the user enters some search text in which case he extends the query with a restrictive clause limiting the result to customers whose names start with the search text.
As he said, IntelliSense does not offer the "Where" method after "_customersQuery" and Visual Studio identifes the entire expression, "Where( c => ...", as something that won't compile.
You can see that he did remember the IdeaBlade.EntityModel "using" statement.
Can you spot the problem? It took me awhile.
Notice that "_customersQuery" is defined as an "IEntityQuery". 
There is no "Where" extension method for IEntityQuery.
Check out IdeaBlade.EntityModel.EntityQueryExtensions in the VS Object Browser window. That's home for most (if not all) of the DevForce LINQ extension method definitions.
"Where" is defined as:

Where<TSource>(this IdeaBlade.EntityModel.IEntityQuery<TSource> source, System.Linq.Expressions.Expression<Func<TSource,int,bool>> predicate)

It extends IEntityQuery<T> ...   IEntityQuery(Of T) if you write in VB.
If our friend changes his definition of the "_customersQuery" member variable to
    IEntityQuery<Customer> _customersQuery;
the "Where" method becomes available.
Happy coding!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down