postman “Sequence contains no elements”错误.Net Core 5

0s7z1bwu  于 12个月前  发布在  Postman
关注(0)|答案(1)|浏览(183)

我的数据库里有两个ID。两个都在我的数据库里。但其中一个工作正常,另一个给出了一个**“序列不包含元素”**错误。

SELECT * FROM Company
where Id ='08db1da9-6bcx' or Id ='08db3387-12as';

这个SQL得到我公司的两个。另外,“{{base_web_url}}/company/008db1da9-6bcx“这个GET方法工作正常,但“{{base_web_url}}/company/08db3387-12as“给出Sequence contains no elements错误。
下面是我的代码,我有麻烦:

var company = await this.mainDbContext.Company
      .Where(x => x.Id == id)
      .Include(x => x.Employees)
      .ThenInclude(x => x.Phones)
      .Include(x => x.Employees)
      .ThenInclude(x => x.Emails)
      .Include(x => x.Logo)
      .ProjectToType<CompanyModel>()
      .FirstOrDefaultAsync()
      .ConfigureAwait(false);
46scxncf

46scxncf1#

错误-该错误基于您使用Linq访问“this.mainDbContext.Company”集合。
当你去“.Where(x => x.Id == id)”时,实际上是“.Where(company => company.Id == id)”
Cultural-问题是“this.mainDbContext.Company”集合是空的,所以它实际上在做的是
“.Where(x => empty == id)”所以编译器运行良好,你让我检查where,但它不可能是where,因为你提供的集合是空的,因此“Sequence contains no elements”

  • 解决方案如果进程在执行过程中由于错误而停止,您需要对如何获取数据流进行排序,如果不是因为进程需要静默处理它并继续,那么您需要处理它或坚持“?'在“this.mainDbContext.Company”之后。

相关问题