I have some methods which perform a standard filter on data from my Entities (using Entity Framework v4).
Example #1:
protected IQueryable
I'd say adding interfaces is a simpler option than messing with the expression tree or reflection. EF entities are partial classes, so you should be able to do something like:
Updated to include class constraint (see Mark's comment)
public interface IHideable
{
string State { get; }
string Hidden { get; }
}
...
namespace Database
{
public partial class Product : IHideable { }
public partial class Customer : IHideable { }
}
...
protected IQueryable GetActive(ObjectSet entities)
where T : class, IHideable
{
var allowedStates = new string[] { "Active" , "Pending" };
return (
from obj in entities
where allowedStates.Contains(obj.State)
&& obj.Hidden == "No"
select obj
);
}