小编rob*_*r08的帖子

在单个LINQ语句中使用.Select和.Where

我需要使用LINQ从特定的表中收集Distinct Id.问题是我还需要一个WHERE语句,它应该仅根据我设置的要求过滤结果.不得不如此使用LINQ相对较新,但我或多或少地使用以下代码:

private void WriteStuff(SqlHelper db, EmployeeHelper emp)
{
    String checkFieldChange;
    AnIList tableClass = new AnIList(db, (int)emp.PersonId);
    var linq = tableClass.Items
        .Where(
           x => x.UserId == emp.UserId 
             && x.Date > DateBeforeChanges 
             && x.Date < DateAfterEffective 
             && (
                     (x.Field == Inserted)
                  || (x.Field == Deleted)))
                )
             ).OrderByDescending(x => x.Id);

    if (linq != null)
    {
        foreach (TableClassChanges item in linq)
        {
            AnotherIList payTxn = new AnotherIList(db, item.Id);
            checkFieldChange = GetChangeType(item.FieldName);

            // Other codes that will retrieve data from each item 
            // and …
Run Code Online (Sandbox Code Playgroud)

c# linq unique distinct

25
推荐指数
2
解决办法
23万
查看次数

标签 统计

c# ×1

distinct ×1

linq ×1

unique ×1