Sak*_*ket 13 linq entity-framework c#-4.0
我有一张表如下:
PersonalDetails
Columns are:
Name  
BankName
BranchName
AccountNo
Address
我有另一个包含'Name'和'AccountNo'的列表.我必须从表中找到所有记录,其中"Name"和"AccountNo"分别出现在给定列表中.
任何建议都会有所帮助.
我做了以下但没有太多用处:
var duplicationhecklist = dataAccessdup.MST_FarmerProfile
                          .Join(lstFarmerProfiles, 
                                t => new { t.Name,t.AccountNo}, 
                                t1 => new { t1.Name, t1.AccountNo}, 
                                (t, t1) => new { t, t1 })
                           .Select(x => new {
                                               x.t1.Name,
                                               x.t1.BankName,
                                               x.t1.BranchName,
                                               x.t1.AccountNo
                                             }).ToList();
lstFarmerProfiles列表在哪里.
Ger*_*old 20
您可能发现无法使用本地实体对象列表加入Entity Framework LINQ查询,因为它无法转换为SQL.我会预先选择帐号上的数据库数据,然后加入内存.
var accountNumbers = lstFarmerProfiles.Select(x => x.AccountNo).ToArray();
var duplicationChecklist = 
        from profile in dataAccessdup.MST_FarmerProfile
                                     .Where(p => accountNumbers
                                                    .Contains(p.AccountNo))
                                     .AsEnumerable() // Continue in memory
        join param in lstFarmerProfiles on 
            new { profile.Name, profile.AccountNo} equals 
            new { param.Name, param.AccountNo}
        select profile
因此,您永远不会将批量数据拉入内存,但您可以继续进行最小的选择.
如果accountNumbers包含数千个项目,您可以考虑使用更好的可扩展的chunky Contains方法.
| 归档时间: | 
 | 
| 查看次数: | 39614 次 | 
| 最近记录: |