I am using entity framework core in my .net core 3.1 application. I have an object like
public class AppEntity
{
[Key]
public int entity_id { get; set; }
[Required]
public string entityname { get; set; }
[Required]
public string short_code { get; set; }
[Required]
public int entitytype_id { get; set; }
public int? parent_id { get; set; }
public AppEntity Parent { get; set; }
}
How can i make my object loaded with parent object on model creating. current code at model creating is
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<AppEntity>(o => { o.HasIndex(e => e.short_code).IsUnique(true); });
builder.Entity<AppEntity>().HasOne(j => j.Parent).WithOne().HasForeignKey<AppEntity>(f => f.parent_id);
}
I am getting exception on modelcreating as
The property or navigation 'Parent' cannot be added to the entity type 'AppEntity' because a property or navigation with the same name already exists on entity type 'AppEntity'.