I have a few lines of code that in a loop that i'd like to refactor as a method. One of the lines is the following
var foo = db.tblA.Where(r => r.bar == old.Value).SingleOrDefault();
However, when I call this method, I need to pass in different tables (tblA, tblB, tblC...) and the WHERE clause will have a different field to compare (r.Name, r.Address, r.Author...)开发者_运维问答
What would the method's signature look like to pass in those two pieces of information?
Like this:
TRow MyMethod<TRow>(IQueryable<TRow> table, Expression<Func<TRow, object>> column)
Depending on your situation, you might want to replace object
with string
or with a second generic parameter.
精彩评论