要檢查,如果在ClientAccessCode表中存在的任何記錄,如果沒有返回false返回false ...如何如果表中不存在的記錄
if (!CheckAccessCodeExists())
{
Console.WriteLine("Client Access code does not exist");
throw new ConfigurationErrorsException("Client Access code does not exist");
}
private static bool CheckAccessCodeExists()
{
using (EPOSEntities db = new EPOSEntities())
{
ClientAccountAccess clientAccess = db.ClientAccountAccesses
.OrderByDescending(x => x.Id)
.Take(1)
.Single();
if (clientAccess != null)
{
return true;
}
return false;
}
}
//這是萎靡不振的序列不包含任何元素,在lamba表達式,那麼我怎麼才能返回false呢?也許使用.Any()?
感謝
編輯 那十分感謝您的幫助球員金正日現在標記的答案,也是另一個查詢,如果我有
ClientAccountAccess clientAccess = db.ClientAccountAccesses
.OrderByDescending(x => x.Id)
.Take(1)
.Single();
if (clientAccess != null)
{
db.DeleteObject(clientAccess);
}
我怎麼能重構這個說事有條理像
if (db.ClientAccountAccesses.Any())
{
db.DeleteObject(//what does in here do I have to use above code to get record to delete?);
}
要刪除所有內容嗎? – James
以及考慮只會有一個記錄在表中,是刪除記錄,但不是實際的表 – John
@約翰看到更新的答案 –