I’m trying to create a generic method to use in my base class for my repositories and I’m having an issue. Here’s the method…
public virtual T First(System.Linq.Expressions.Expression<Func<T, bool>> where, List<string> properties)
{
IQueryable<T> query = null;
if (where != null)
{
query = _context.CreateQuery<T>(String.Format("[{0}]", typeof(T).Name.ToString())).Where(where);
}
else
{
query = _context.CreateQuery<T>(String.Format("[{0}]", typeof(T).Name.ToString()));
}
foreach (string s in properties)
{
query = query.Include(s);
}
T _result = (T)query.First();
return _result;
}
When I run the code it gives me this error:
‘Company’ could not be resolved in
the current scope or context. Make
sure that all referenced variables are
in scope, that required schemas are
loaded, and that namespaces are
referenced correctly. Near escaped
identifier, line 1, column 1.
I have an idea on why it’s doing this, I just don’t know how to fix it. I think it’s doing it because my ObjectContext doesn’t know about the object “Company” but it does know “Companies”. Any ideas on how to fix this??
The error happens on this line:
T _result = (T)query.First();
Thanks!
Try to use
instead of