Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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# ASP.NET Core 2.2 IdentityUser未与模型一起检索_C#_Linq_Razor_Asp.net Core 2.2_Ef Core 2.2 - Fatal编程技术网

C# ASP.NET Core 2.2 IdentityUser未与模型一起检索

C# ASP.NET Core 2.2 IdentityUser未与模型一起检索,c#,linq,razor,asp.net-core-2.2,ef-core-2.2,C#,Linq,Razor,Asp.net Core 2.2,Ef Core 2.2,我有一个模型,它有一个IdentityUser类型的属性,如下所示: public class Foo { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int ID { get; set; } // working properties omitted public IdentityUser LastChangeBy { get; set; } } 当我尝试使用

我有一个模型,它有一个IdentityUser类型的属性,如下所示:

public class Foo {
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int ID { get; set; }

    // working properties omitted

    public IdentityUser LastChangeBy { get; set; }
}
当我尝试使用efcore从DB检索模型时,我没有得到任何错误,但是
LastChangeBy
属性是
null
,即使它是使用(有效)用户创建的。我甚至将用户表中的ID与模型表中的ID进行了双重检查

模型中我的(无可否认是天真的)LINQ如下所示:

Foos = from foo in db.Foos
       select foo;
控制台上没有打印错误,站点正常加载,断点显示,直接来自数据库的用户已
null
。我没有修改DbContext中默认设置的任何设置(该设置源自
IdentityDbContext
),并且应用了当前迁移


你知道是什么原因吗?

@GertArnold它不应该加载丢失的东西,但要慢一点吗?我也没有将
LastChangeBy
属性声明为虚拟。不,EF core没有默认的延迟加载。@GertArnold哦,我习惯于EF 6。。。你能给我一个完整的答案吗?这样我就可以接受了?