Print Page | Close Window

"Where" not showing in IntelliSense

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1743
Printed Date: 07-Jun-2024 at 7:21pm


Topic: "Where" not showing in IntelliSense
Posted By: WardBell
Subject: "Where" not showing in IntelliSense
Date 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!



Print Page | Close Window