That is a bit untypical 'setup' (and it's usually designated via some 'flag' on the item - but I can possibly see a need for something similar), and relating one item to the same parent twice.
However, this should work...
modelBuilder.Entity<SomeEntity>()
.HasOptional(x => x.DefaultItem)
.WithOptionalPrincipal() // x => x.DefaultForEntity)
.WillCascadeOnDelete(false);
...
// public SomeEntity DefaultForEntity { get; set; } // optional
...and use it like:
var item = new Item { ItemName = "Default1", };
db.SomeEntities.Add(new SomeEntity { DefaultItem = item, Items = new[]
{
item,
new Item{ ItemName = "Item1", },
new Item{ ItemName = "Item2", },
new Item{ ItemName = "Item3", },
new Item{ ItemName = "Item4", },
}
});
db.SaveChanges();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…