我有一个函数应该返回参数传递的元素的Id,例如:
public static Int32 getIdByName(string name)
{
var query = from student in DataAccess.getInstance.StudentSet
where student.FirstName.Equals(name)
select student;
return toto;
}
我不知道如何将结果toto
转换为Int32并将其返回!!
答案 0 :(得分:2)
return DataAccess.getInstance.StudentSet.Last(s => s.FirstName == name).Id;
答案 1 :(得分:1)
public static Int32 getIdByName(string name)
{
var query = from student in DataAccess.getInstance.StudentSet
where student.FirstName.Equals(name)
select student.Id;
return query.First();
}