I wanted to have a view to add a few extra proprieties and I tried the following:
Base table:
namespace Core.Model {
public class Item
{
[Key]
public int ItemId { get; set; }
[Required]
public ItemType Type { get; set; }
[Required]
[MaxLength(255)]
public string Name { get; set; }
//...
}
}
extended view:
namespace Core.Model
{
public class ItemExtended : Item
{
public int? CommentsCount { get; set; }
}
}
Then in the Context I have:
public DbSet<QuiverItemExtended> ItemsExtended { get; set; }
modelBuilder.Entity<ItemExtended>()
.ToTable("ItemsExtended")
.HasKey(view => new { view.ItemId });
This works for querying but when I try to insert a normal Item I get this exception:
All objects in the EntitySet 'Context.Items' must have unique primary keys. However, an instance of type 'Core.Model.ItemExtended' and an instance of type 'Core.Model.Item' both have the same primary key value, 'EntitySet=Items;ItemId=1097'.
Any ideias how I can fix this?
thanks in advance