Reputation: 3787
I want to turn this into a function. I will be passing the db object and the MVC model object. Here is the original code:
var SomethingApproval = db.Somethings.AsQueryable();
var predicate = PredicateBuilder.True<Something>();
predicate = predicate.And(p => p.Approved == "N");
SomethingApproval = SomethingApproval.AsExpandable().Where(predicate);
I want a function like this
Function ApprovedItems (dbObject, modelObject)
{
var SomethingApproval = dbobject.AsQueryable();
var predicate = PredicateBuilder.True<modelObject>();
predicate = predicate.And(p => p.Approved == "N");
SomethingApproval = SomethingApproval.AsExpandable().Where(predicate);
return SomethingApproval
}
Upvotes: 0
Views: 205
Reputation: 15772
Going out on a limb here... think its a generics question
public IQueryable<T> ApprovedItems<T>(DbObject db)
where T : IApprovable
{
var query = db.Set<T>();
return query.Where(p => p.Approved == "N");
}
public interface IApprovable
{
//By the way I do not Approve of an
//approve flag with type of string
string Approved {get;}
}
Upvotes: 1