我有两个实体
User { UserID, Name, UserTypeID }
StudentParent { StudentParentID, StudentID, ParentID }
// where
UserTypeID { 1=student, 2=parent }
StudentParent.StudentID
和StudentParent.ParentID
都是指向User.UserID
的外键
我有一个学生列表(IEnumerable<User>
),我需要为其获取家长列表。我需要帮助找出正确的表达来得到父母的名单。
我应该使用contains或any语句来匹配学生用户列表吗?
发布于 2011-09-22 08:58:24
您应该能够从您的IEnumerable
of students中Select
出Parent
实体。
students.SelectMany(s => s.StudentParents.Select(sp => sp.ntParent_Parent));
这将从您的学生集合中执行投影,而不是所有Students
。
从逻辑上讲,它类似于
这是一组
选择匿名类型也可能更有用,这样您就可以看到哪些家长属于哪些学生。
students.Select(s => new {
Student = s,
Parents = s.StudentParents.Select(sp => sp.ntParent_Parent))});
https://stackoverflow.com/questions/7508141
复制相似问题