0

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
}
tereško
  • 58,060
  • 25
  • 98
  • 150
Barry MSIH
  • 3,525
  • 5
  • 32
  • 53

1 Answers1

1

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;}
}
Aron
  • 15,464
  • 3
  • 31
  • 64