嗨,我尝试从我的数据库中获取一些日期,但它不起作用,我真的不知道为什么。
我收到以下错误:
Error: Entities in 'DataBase' participate in the 'FK_MSCourse_Language' relationship. 0 related 'Language' were found. 1 'Language' is expected.
我的代码:
var language = db.Language.Where(x => x.Designation == publicLanguage);
if (language != null)
{
newCourse.Language = language.SingleOrDefault();
}
else
{
newCourse.Language = db.Language.SingleOrDefault(x => x.Designation == "English");
}
如果我这样做它可以工作,但我想将它动态地从数据库中转换为语言。
switch (publicLanguage)
{
case "French":
newCourse.Language = db.Language.SingleOrDefault(x => x.Designation == "French");
break;
default:
newCourse.Language = db.Language.SingleOrDefault(x => x.Designation == "English");
break;
}
有人知道我在做什么错吗?
谢谢,马库斯