在将数据从 db1 复制到 db2 后,我正在对数据完整性进行大量测试。
我一直在写几乎相同的测试,这是伪代码
Get db1List
Get db2list
for each db2poco in db2list
linq to get list of db1pocos.membervaribale1 matches db2poco.membervaribale1
if db1pocos.membervaribale2 == db2poco.membervaribale2
return false
return true
我想将它转换为一个通用方法,该方法采用泛型和 lambdas 进行比较......有点像这样,除了它不编译......
private bool GenericCompareLists<T1, T2>(List<T1> cdssList, List<T2> spamisList, object sender, Func<bool, T1, T2> filterLambda , Func<bool, T1, T2> compareLambda )
{
bool passed = true;
foreach ( T2 spamisCv in spamisList )
{
List<T1> cdssSubList = ( from l in cdssList where filterLambda( l, spamisCv ) select l ).ToList();// should alwasy be one,
if ( cdssSubList.Count != 1 )
{
log.Error( "..." );
passed = false;
}
else
{
T1 cdssCv = cdssSubList.First();
if ( compareLambda( cdssCv, spamisCv) )// comparing the sum of all check_amt for this type, cdss vs spamis - EWB
{
log.Error( "Failed in comparison f" + sender.ToString() );
passed = false;
}
}
}
return passed;
}
但我无法弄清楚如何让它真正工作/调用它。
有人可以帮帮我吗?或指出我的 lambda fu 的好参考...