【发布时间】:2017-12-21 17:58:07
【问题描述】:
大家好,我正在尝试使用以下代码在 .NET MVC 中的 C# 中的 LINQ 中进行查询:
public int Delete(int id)
{
using (DBEntities db = new DBEntities())
{
var student = db.Students.Find(id);
var curso = from t in db.Teachers
join i in db.Inscriptions on id equals i.StudentId
where t.Id == i.StudentId
select i.Id;
var atten = from a in db.Attendances
where a.InscriptionId == curso
}
}
我正在尝试将我正在执行的查询与已包含值的变量进行比较。
我想比较一下:where a.InscriptionId == curso
Curso 是包含我需要比较的值的变量。
我该怎么做?
【问题讨论】:
-
curso 的值类型可能需要转换为整数(或您尝试比较的任何数据类型)。
where a.InscriptionId == (int)curso -
你
curso从查询中返回IEnumerable<>,不管你知道它只会有 0 或 1 个元素。所以你需要做类似var cursoId = curso.FirstOrDefault()然后使用 cursoId 代替 -
@NSGaga 你应该发表你的评论作为答案。
-
@NetMage 我猜你是对的。
标签: c# asp.net asp.net-mvc linq