Better collection/sub entity creation
This commit is contained in:
parent
2511722400
commit
fde6a8012c
|
|
@ -197,7 +197,10 @@ public abstract class CommonDbContext : DbContext
|
|||
var nav = candidates?.FindNavigation(navigationName);
|
||||
var entityT = nav?.TargetEntityType;
|
||||
|
||||
if (entityT == null || entityT.IsOwned())
|
||||
if (entityT == null)
|
||||
return new T();
|
||||
|
||||
if (entityT.IsOwned())
|
||||
{
|
||||
/*
|
||||
var source = this.GetService<IStructuralTypeMaterializerSource>();
|
||||
|
|
@ -222,30 +225,24 @@ public abstract class CommonDbContext : DbContext
|
|||
|
||||
if (!nav.IsCollection)
|
||||
{
|
||||
var refVal = Entry(parentI).Reference(navigationName);
|
||||
var parEnt = Entry(parentI);
|
||||
var refVal = parEnt.Reference(navigationName);
|
||||
refVal.CurrentValue = val;
|
||||
if (refVal.TargetEntry == null)
|
||||
throw new Exception();
|
||||
|
||||
refVal.TargetEntry.State = EntityState.Added;
|
||||
}
|
||||
else
|
||||
{
|
||||
var refVal = Entry(parentI).Collection(navigationName);
|
||||
if (refVal.CurrentValue is ICollection<T> coll)
|
||||
{
|
||||
coll.Add(val);
|
||||
}
|
||||
}
|
||||
|
||||
//this.ChangeTracker.DetectChanges();
|
||||
|
||||
/*
|
||||
var refVal = this.Set<TParent>()
|
||||
.Entry(parentI)
|
||||
.Reference(navigationName);
|
||||
|
||||
refVal.CurrentValue = val;
|
||||
|
||||
Attach(val);
|
||||
|
||||
if (refVal.TargetEntry == null)
|
||||
throw new Exception("test");
|
||||
*/
|
||||
|
||||
config?.Invoke(val);
|
||||
this.ChangeTracker.DetectChanges();
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user