如何将正确的参数传递给该方法、.net EF4、表名、where 子句
我有几行代码在循环中,我想将其重构为方法。其中一行如下
var foo = db.tblA.Where(r => r.bar == old.Value).SingleOrDefault();
但是,当我调用此方法时,我需要传入不同的表(tblA、tblB、tblC ...),并且 WHERE 子句将有一个不同的字段进行比较(r.Name、r.Name)。地址,r.Author...)
传递这两条信息的方法签名会是什么样子?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样:
根据您的情况,您可能需要将
object
替换为string
或第二个泛型参数。Like this:
Depending on your situation, you might want to replace
object
withstring
or with a second generic parameter.