All of my entities have a base class:
public class Entity<TKey> : IEntity<TKey>
{
dynamic IEntity.Id
{
get
{
return this.Id;
}
set
{
this.Id = value;
}
}
public TKey Id { get; set; }
}
For example Status entity:
[MetadataType(typeof(StatusMetadata))]
public partial class Status : Entity<byte>
{
public string Title { get; set; }
}
When I run the query against the database I get the following error: "The item with identity 'Id' already exists in the metadata collection. Parameter name: item". Is there any way to fix this or it's an issue caused by inheritance and I can't inherit my entities from any class?
The reason is because you inherit from a class that already has an Id property of a different type.
I have seen the same error in CodeMigrations. I had a property named "Version" of type string, and the EntityData data class where I was inheriting from also containes a Version property of type byte[]. This generated the same error as you mentioned
The solution for this is just to don't use the same property names that are already in your base class.