0
delete  from detail where autoid not in (select min(autoid) from detail
where CATEGORY<>'Accepted'
group by ATM_Id, Date, Card ,Transit ,Ck)
and CATEGORY<>'Accepted'

我尝试了什么

     var Query2 = from line in
     (from line in source let fields = line.Split(',')
     select new {  autoid = fields[0],
          ATMID = fields[4],
          DATE = fields[2],
          CARDNo = fields[5],
          TRANSIT = fields[8],
          CheckNo = fields[9],
          CATEGORY = fields[10],
      })
      orderby line.ATMID, 
              line.DATE, 
              line.CARDNo, 
              line.TRANSIT, 
              line.CheckNo ascending
      where   line.CATEGORY != "Accepted"
      group line by new {   line.ATMID,
                            line.DATE, 
                            line.CARDNo, 
                            line.TRANSIT, 
                            line.CheckNo } 
      into gruoped
      where gruoped.Count() > 1

                 //select autoid = gruoped.Key;
      select new
      {
                     //ATMID = gruoped.Key,
                     //DATE = gruoped.Key,
                     //CARDNo = gruoped.Key,
                     //TRANSIT = gruoped.Key,
                     //CheckNo = gruoped.Key,
                     autoid = gruoped.Key,
                     //CATEGORY = gruoped.Key
      };
4

2 回答 2

0

你可以试试这个。

var ids = (from d in detail
where d.Category != "Accepted"
group d by new {d.ATM_Id, d.Date, d.Card ,d.Transit ,d.Ck} into grp
select  grp.Min(x => x.autoId));


var toDelete = (from d in detail
            where !ids.Contains(d.AutoId) && d.Category != "Accepted"
            select d);

context.DeleteOnSubmit(toDelete);   

您可以只搜索所需的内容,然后重新创建新的逗号分隔字符串列表以存储回文件。

例如:

void Main()
{

    var fields = new List<Field>{
        new Field{Id = 1, Name = "A"},
        new Field{Id = 1, Name = "A"},
        new Field{Id = 2, Name = "B"},
        new Field{Id = 1, Name = "A"},
        new Field{Id = 3, Name = "C"},
        new Field{Id = 2, Name = "B"},
    };

    // Grouped 
    var grouped = (from f in fields
                group f by new {f.Id, f.Name} into grp
                select new Field
                {
                        Id = grp.Select(x => x.Id).FirstOrDefault(),
                        Name = grp.Select(x => x.Name).FirstOrDefault()
                }
                );

    // Makes a list of the distinct Fields             
    var list_Of_CSV_Items = grouped.Select(x => string.Join(",", x.Id,x.Name));

    System.IO.File.WriteAllLines(@"C:\Where_your_folder_is.txt", list_Of_CSV_Items);
}

public class Field
{
    public int Id {get;set;}
    public string Name {get; set;}
}         
于 2013-06-12T13:50:23.230 回答
0

这是一个示例,它应该如何工作检查一下

var remove = (from aremove in db.logins 
             where aremove.username == userNameString 
                && aremove.Password == pwdString 
             select aremove).FirstOrDefault(); 

if(remove != null)
{
    db.logins.DeleteOnSubmit(remove);
}

如果您有任何问题,请随时提问!

于 2013-06-12T12:05:23.453 回答