I'm playing around with EF Core 3 and writing some unit tests and don't seem to be able to setup test data for a view.
When I'm trying to save, I get the error:
Unable to track an instance of type because it does not have a primary key. Only entity types with primary keys may be tracked
public class EFContext : DbContext
{
public DbSet<ViewItem> ViewItems { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ViewItem>().HasNoKey().ToView("vTestView");
}
}
using (EFContext efContext = new EFContext())
{
efContext.ViewItems.Add(new ViewItem
{
Name = "This is test item #1"
});
efContext.SaveChanges();
}