views:

10

answers:

1

Linq to Entities uses the ObjectQuery which implements IQueryable. I normally use the IQueryable methods to filter through my data but today I needed to create a special LIKE statement. The framework keeps thinking its smart and "escaping" my wildcard "%" with the tilde which rendered my special LIKE statement null and void. So after digging around I found that ObjectQuery has an overload for the Where method on it that allows you to pass a string along with ObjectParameters. I've done this but it doesn't execute as the IQueryable did. When I run the application nothing happens after this code is hit. No errors, and no hits on the database either so I know the query I've created isn't actually executing.

How do I execute this puppy?

    public IQueryable<tbl_Path> GetPathsByWildCardSearch(string searchTerm)
    {
        return this.ObjectContext.tbl_Path
            .Where("FullPath NOT LIKE @p0 and FullPath LIKE @p1", 
                new ObjectParameter("p0", string.Format("%{0}%{1}%", searchTerm, tbl_Path.PathSeperator)),
                new ObjectParameter("p1", string.Format("%{0}%", searchTerm)));
    }
A: 

;) finally saw there was an Execute() method on it.

JoeyBradshaw