我的数据库里有两个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);
1条答案
按热度按时间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”