Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#如何从数据库中的元素中查找id_C#_Database_Primary Key - Fatal编程技术网

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

c#如何从数据库中的元素中查找id,c#,database,primary-key,C#,Database,Primary Key,如何从值english中获取id,一直在搜索,没有任何答案。 谢谢你的帮助 test.CourseId = await _context.Course.FirstOrDefaultAsync(m => m.Schulfach == english); 您的代码检索整个对象。您需要访问此对象的单个属性: var course = await _context.Course.FirstOrDefaultAsync(m => m.Schulfach == english); if (co

如何从值
english
中获取
id
,一直在搜索,没有任何答案。 谢谢你的帮助

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

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

var course = await _context.Course.FirstOrDefaultAsync(m => m.Schulfach == english);
if (course != null)
{
    test.CourseId = course.CourseId;
}