c#如何从数据库中的元素中查找ID

问题描述 投票:0回答:1

test.CourseId =等待_context.Course.FirstOrDefaultAsync(m => m.Schulfach == english);

我如何从英语值中获取ID,一直搜索都没有任何答案。感谢您的帮助

c# database id
1个回答
0
投票

您的代码将检索整个对象。您需要访问一个属性:

var course = await _context.Course.FirstOrDefaultAsync(m => m.Schulfach == english);
if (course != null)
{
    test.CourseId = course.CourseId;
}
© www.soinside.com 2019 - 2024. All rights reserved.