DbContext
has a method called Set
, that you can use to get a non-generic DbSet
, such as:
var someDbSet = this.Set(typeof(SomeEntity));
So in your case:
foreach (BaseEntity entity in list)
{
cntx.Set(entity.GetType()).Add(entity);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…