将 Linq 查询转换为 Lambda
Converting Linq query to Lambda
如何将以下 linq to sql 转换为 lambda 表达式。谢谢
var existing = (from a in db.sms_imported_trn_code
where !db.sms_description.Any(m => m.trn_code == a.trn_code)
select new { trn_code = a.trn_code }).ToList();
编辑:
我尝试了以下查询,但它给了我一个错误。请查看下图。
我的模型类如下
public class sms_imported_trn_code
{
public int id { get; set; }
public string trn_code { get; set; }
List<sms_imported_trn_code> sms_import_list { get; set; }
}
}
public class sms_description
{
public int id { get; set; }
public string trn_code { get; set; }
public string Description { get; set; }
[DisplayFormat(DataFormatString = "{0:MMM-dd-yyyy}", ApplyFormatInEditMode = true)]
public DateTime create_date { get; set; }
public string created_by { get; set; }
}
您收到错误是因为您正在编写 "s.sms_description",sms_description 不是 class sms_imported_trn_code 的一部分,它是一个单独的 class,因此您需要写 db.sms_description
db.sms_imported_trn_code
.Where(s => !db.sms_description.Any(m => m.trn_code == s.trn_code))
.Select(t => new {trn_code = t.trn_code }).ToList();
如何将以下 linq to sql 转换为 lambda 表达式。谢谢
var existing = (from a in db.sms_imported_trn_code
where !db.sms_description.Any(m => m.trn_code == a.trn_code)
select new { trn_code = a.trn_code }).ToList();
编辑:
我尝试了以下查询,但它给了我一个错误。请查看下图。
我的模型类如下
public class sms_imported_trn_code
{
public int id { get; set; }
public string trn_code { get; set; }
List<sms_imported_trn_code> sms_import_list { get; set; }
}
}
public class sms_description
{
public int id { get; set; }
public string trn_code { get; set; }
public string Description { get; set; }
[DisplayFormat(DataFormatString = "{0:MMM-dd-yyyy}", ApplyFormatInEditMode = true)]
public DateTime create_date { get; set; }
public string created_by { get; set; }
}
您收到错误是因为您正在编写 "s.sms_description",sms_description 不是 class sms_imported_trn_code 的一部分,它是一个单独的 class,因此您需要写 db.sms_description
db.sms_imported_trn_code
.Where(s => !db.sms_description.Any(m => m.trn_code == s.trn_code))
.Select(t => new {trn_code = t.trn_code }).ToList();