How do you use GetAllBlah() from the Repository?

Mar 2, 2011 at 6:26 AM
Edited Mar 2, 2011 at 6:31 AM

The auto generated repository has the method like this

 

        public IEnumerable<Blah> GetAllBlahs(params Expression<Func<Blah, object>>[] includeProperties)
        {
            IQueryable<Blah> query = context.Blahs;
            foreach (var includeProperty in includeProperties) {
                query = query.Include(includeProperty);
            }
            return query.ToList();
        }

 

Can someone provide a good example on how to write a LINQ Expression that works with this method? I am hitting some brick walls here :( Thanks!

At first I thought I could do something like 

 

Expression<Func<Blah, object>> myExp = blah => blah.foo.Equals(bar); // where bar is string type key value used to look up an entry of Blah type
Blah foundBlah = (new BlahRepository()).GetAllBlahs(myExp).First();

 

But then, I get an error, like

The include path expression must refer to a property defined by the entity, optionally also with nested properties or calls to Select.
Parameter name: path

 

Line 17:             IQueryable<Blah> query = context.Blahs;
Line 18:             foreach (var includeProperty in includeProperties) {
Line 19:                 query = query.Include(includeProperty);
Line 20:             }
Line 21:             return query.ToList();
 

 

What did I do wrong?