C# EF core不会插入InMemoryDatabase的所有记录
你好 我无法使用InMemory数据库在EF core中插入多条记录。我所说的失败是指它可以工作,但它似乎并没有插入所有记录 这是我要插入的代码:C# EF core不会插入InMemoryDatabase的所有记录,c#,.net,entity-framework,.net-core,C#,.net,Entity Framework,.net Core,你好 我无法使用InMemory数据库在EF core中插入多条记录。我所说的失败是指它可以工作,但它似乎并没有插入所有记录 这是我要插入的代码: var f1= new F1[]{ /* Where I have populated this*/} await context.F1.AddRangeAsync(f1); var f2= new F2[]{ /* Where I have populated this*/}
var f1= new F1[]{ /* Where I have populated this*/}
await context.F1.AddRangeAsync(f1);
var f2= new F2[]{ /* Where I have populated this*/}
await context.f2.AddRangeAsync(f2);
var f3= new F3[]{ /* Where I have populated this*/}
await context.F3.AddRangeAsync(f3);
var f4= new F4[]{ /* Where I have populated this*/}
await context.F4.AddRangeAsync(f4);
var f5= new F5[]{ /* Where I have populated this*/}
await context.F5.AddRangeAsync(f5);
var f6= new F6[]{ /* Where I have populated this*/}
await context.F6.AddRangeAsync(f6);
var f7= new F7[]{ /* Where I have populated this*/}
await context.F7.AddRangeAsync(f7);
await context.SaveChangesAsync();
其中每个集合至少有2个项目,最多有100个项目
运行此代码后:
var f1= await context.F1.ToListAsync();
var f2= await context.F2.ToListAsync();
var f3= await context.F3.ToListAsync();
var f4= await context.F4.ToListAsync();
var f5= await context.F5.ToListAsync();
var f6= await context.F6.ToListAsync();
var f7= await context.F7.ToListAsync();
和断点后的f7行和鼠标悬停在集合,我可以看到他们都只有一部分的项目
以下是创建内存中数据库的方法:
services.AddDbContext<FamousDbContext>(opt => opt.UseInMemoryDatabase("MyFamousDatabase"));
当我从所有对象中删除对象引用并只留下F1Id时,它就像一个符咒 你有没有试着把这些项目打印出来?可能调试器没有显示所有项?可能尝试计数()-正在对项目进行计数?您使用的是什么版本的.NET Core和EF Core?@Euphoric我尝试了对数据库执行两个不同的请求,并检查了即时窗口中的计数。每次运行时数据库中的项目是否相同或不同?是否可以从数据库中的项目和不在数据库中的项目中分辨出什么?每次运行它们都是相同的。每次运行时,数据库都会预填充相同的项。我尝试更改InMemory数据库的名称,但仍然是一样的@兴高采烈的
public int F1Id {get;set}
public F1 F1 {get;set;}