开发者

How to pass the correct parameters to this method, .net EF4, table names, where clauses

开发者 https://www.devze.com 2023-01-31 11:52 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号