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 nav = candidates?.FindNavigation(navigationName);
|
||||||
var entityT = nav?.TargetEntityType;
|
var entityT = nav?.TargetEntityType;
|
||||||
|
|
||||||
if (entityT == null || entityT.IsOwned())
|
if (entityT == null)
|
||||||
|
return new T();
|
||||||
|
|
||||||
|
if (entityT.IsOwned())
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
var source = this.GetService<IStructuralTypeMaterializerSource>();
|
var source = this.GetService<IStructuralTypeMaterializerSource>();
|
||||||
|
|
@ -222,30 +225,24 @@ public abstract class CommonDbContext : DbContext
|
||||||
|
|
||||||
if (!nav.IsCollection)
|
if (!nav.IsCollection)
|
||||||
{
|
{
|
||||||
var refVal = Entry(parentI).Reference(navigationName);
|
var parEnt = Entry(parentI);
|
||||||
|
var refVal = parEnt.Reference(navigationName);
|
||||||
refVal.CurrentValue = val;
|
refVal.CurrentValue = val;
|
||||||
if (refVal.TargetEntry == null)
|
if (refVal.TargetEntry == null)
|
||||||
throw new Exception();
|
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);
|
config?.Invoke(val);
|
||||||
|
this.ChangeTracker.DetectChanges();
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user