我有一个包含许多表的答案的数据库。如果可能的话,我不想为每个表编写相同的代码:
answersDataContext adc = new answersDataContext();
var a0 = (from p in adc.answersfios
where p.userid == userrecord.id
select p);
var a0 = (from p in adc.answersdates
where p.userid == userrecord.id
select p);
更新:问题如下: 我有很多桌子,如果有可能我想写点像
var a0 = (from p in adc. ALLTABLES
where p.userid == userrecord.id
select p)
答案 0 :(得分:0)
public static IEnumerable<MyEntity> GetByUser(this IEnumerable<MyEntity> source, UserEntity userrecord)
{
return source.Where(w=>w.userid == userrecord.id);
}
或每个继承的通用方式:
public static IEnumerable<T> GetByUser(this IEnumerable<T> source, UserEntity userrecord) where T: MyEntity
{
return source.Where(w=>w.userid == userrecord.id);
}
你可以像以下一样使用它:
var a0 = adc.answersfios.GetByUser(userrecord);