我有下表是sql
Id / transaction
15 .4785-t48 er8-565
24 x 4587-dsfs-89554
784 x 5sd 487-89d5-5SD
在我的程序中,我传入了一个事务,其中我首先需要检查数据库中是否存在事务,如下所示
var entry = (await _Repository.AsQueryableAsync()).FirstOrDefault(x => x.transaction == command.transaction);
if (entry !=null)
{
// do something
}所以,上面的工作。我的问题是存在的事务,如何检查该事务是否等于传入的id
例如,如果我将下面的响应从api中传递给
"transaction": "4785-t48er8-565",
"id":569 然后,它将使用上面的代码检查事务是否存在。现在您可以在表中看到,事务4785-t48er8-565的id为15,但在响应中,我传递了569。
如何检查事务是否与id匹配。我需要先检查它是否存在,然后将它与id匹配。
发布于 2020-05-21 13:21:14
您可以将它添加到您已经具备的相同条件中,例如:
var entry = (await _Repository.AsQueryableAsync()).FirstOrDefault(x => x.transaction == command.transaction);
if (entry !=null)
{
if (entry.id != command.id)
{
// then it already exists for a different id
}
else
{
//then entry is the one that matches transaction and id
}
}如果不满足这两个属性的条件,则entry将为空。
发布于 2020-05-21 13:33:20
如果您需要先测试事务,然后在Id上单独测试,请尝试:
var entry = (await _Repository.AsQueryableAsync()).FirstOrDefault(x => x.transaction == command.transaction);
if (entry == null)
{
// do no transaction stuff
}
else if (entry.Id == command.Id)
{
// do matching stuff
}
else
{
//do transaction found but Id doesn't match stuff
}https://stackoverflow.com/questions/61935427
复制相似问题