使用Linq将数据检索到SelectListItem

时间:2012-10-17 05:51:18

标签: linq entity-framework linq-to-sql

我有班级studentList

 public class studentList
    {
    public static IEnumerable<SelectListItem> GetStudents(int? ID)
            {
//code is required here
    return ;
            }
        }

我在这个方法中获取ID,现在,我需要表中的所有其他ID,不包括使用linq传递的参数ID。

我有Student表,其中包含两个fieds StudentID和StudentName, 现在我需要上述模式中学生的ID和姓名.. 任何人都可以帮助我......

1 个答案:

答案 0 :(得分:0)

可能喜欢阅读:SQL to LINQ ( Visual Representation )

   var data= form s in Students
     where s.StudentID != ID
    select new {ID= s.StudenID,Name = s.StudentName};

图像展示可能就像

enter image description here