我正在嘗試做與我在 ef core 中使用不在命令中的 SQL 所做的相同的事情。
var studentsForTeam = await api.GetAllStudentsByTeamId(item.TeamId);
SessionId = item.Id;
TeamId = item.TeamId;
List<SessionStudent> studentsToRemove = await api.GetALLStudentsSessions();
// we want to remove the students that have alreeady arrived for a session.
var alreadyAttendend = studentsToRemove.Where(x=>x.isAbesent==false &&
x.isArrived==true).Select(x => x.StudentId );
var studentsnotArrvied = studentsToRemove.Where(w=>w.isAbesent==false &&
!alreadyAttendend.Contains(w.Id) ).ToList();
//I only want this to produce buttons for students that have not already checked in.
CheckInButtonsStudents(studentsForTeam);
所以例如我有
學生表
| 學生卡 | 描述 |
|---|---|
| 117 | 博士 |
| 118 | 瑪莎瓊斯 |
我有學生會話表
| 季節 ID | 學生卡 | 缺席 | 到了 |
|---|---|---|---|
| 86 | 117 | 錯誤的 | 真的 |
| 87 | 118 | 真的 | 錯誤的 |
所以我需要我上面的查詢做的是學生會話學生 ID 在學生會話中存在的位置,其中 isAbsent false 和 isArrived true 以將其從學生中排除以進行團隊查詢。
這是我的登記功能
public async void CheckInButtonsStudents(ObservableCollection<Student> students)
{
string name = string.Empty;
checkinButtons.Children.Clear(); //just in case so you can call this code several times np..
foreach (var item in students)
{
var btn = new Button()
{
AutomationId = StudentId.ToString(),
BackgroundColor = Color.Blue,
TextColor = Color.White,
Text = item.FirstName " " item.Surname,
};
btn.BindingContext = item; // add this here
btn.Clicked = BtnStudents_Clicked;
checkinButtons.Children.Add(btn);
}
}
uj5u.com熱心網友回復:
所以我需要我上面的查詢做的是學生會話學生 ID 在學生會話中存在的位置,其中 isAbsent false 和 isArrived true 以將其從學生中排除以進行團隊查詢。
如果我理解正確,您希望所有學生都來自studentsForTeam學生會話中學生 ID 所在的位置,并且學生會話 isArrived 但不是 isAbsent?
我們已經在alreadyAttended(isArrived && !isAbsent) 中設定了學生會話。所以我們可以過濾studentsforTeamid 為 in 的學生alreadyAttended。
var studentsForCheckIn = studentsForTeam
.Where(s => alreadyAttended.Contains(s.id))
.ToList();
CheckInButtonsStudents(studentsForCheckIn);
然后,我建議您稍微簡化一下代碼:
// I think you have a typo here: use isAbsent instead of isAbesent
// Don't compare for == true or == false. !isAbsent is the same as isAbsent == false
var alreadyAttendend = studentsToRemove
.Where(x => !x.isAbsent && x.isArrived)
.Select(x => x.StudentId);
// Here you select students that are not absent AND not in alreadyAttendend.
// That's the same as not absent and not arrived. If you write it like that, it's easier to read
var studentsNotArrvied = studentsToRemove
.Where(w => !w.isAbsent && !w.isArrived).ToList();
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/314655.html
