[英]Using GraphDiff on three tables
I have three tables 我有三张桌子
ShippingZone
ShippingZoneID -> PK
ZoneShippingMethod:
ZoneShippingMethodID -> PK
ShippingZoneID -> FK
ZoneShippingMethodRange
ZoneShippingMethodID -> FK
The context: 上下文:
public ShippingZonesContext()
: base("name=ShippingZonesContext")
{
}
public virtual DbSet<ShippingZone> ShippingZones { get; set; }
public virtual DbSet<ZoneShippingMethod> ZoneShippingMethods { get; set; }
public virtual DbSet<ZoneShippingMethodRange> ZoneShippingMethodRanges { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<ShippingZone>()
.Property(e => e.ZoneCountryIDs)
.IsUnicode(false);
modelBuilder.Entity<ShippingZone>()
.Property(e => e.ZoneStateIDs)
.IsUnicode(false);
modelBuilder.Entity<ShippingZone>()
.HasMany(e => e.ZoneShippingMethods)
.WithRequired(e => e.ShippingZone)
.WillCascadeOnDelete(false);
modelBuilder.Entity<ZoneShippingMethod>()
.Property(e => e.UserID)
.IsUnicode(false);
modelBuilder.Entity<ZoneShippingMethod>()
.Property(e => e.Password)
.IsUnicode(false);
modelBuilder.Entity<ZoneShippingMethod>()
.Property(e => e.ShippingServiceTypeIDs)
.IsUnicode(false);
modelBuilder.Entity<ZoneShippingMethod>()
.Property(e => e.AccessKey)
.IsUnicode(false);
modelBuilder.Entity<ZoneShippingMethod>()
.Property(e => e.ShipperNumber)
.IsUnicode(false);
modelBuilder.Entity<ZoneShippingMethod>()
.HasMany(e => e.ZoneShippingMethodRanges)
.WithRequired(e => e.ZoneShippingMethod)
.WillCascadeOnDelete(false);
}
Current code: 当前代码:
context.UpdateGraph(shippingZone, map => map
.OwnedCollection(p => p.ZoneShippingMethods).OwnedCollection(p => p.ZoneShippingMethods.FirstOrDefault().ZoneShippingMethodRanges)
);
Gives this error: 给出此错误:
The method used in the update mapping is not supported
不支持更新映射中使用的方法
Any clues? 有什么线索吗?
Thanks & Regards. 感谢和问候。
Your mapping is using FirstOrDefault
which isn't supported in GraphDiff mappings, so this is producing the error. 您的映射是使用
FirstOrDefault
未在GraphDiff映射支持,所以这是产生误差。
The correct mapping in your case looks like this: 您的情况下正确的映射如下所示:
context.UpdateGraph(shippingZone,
map => map.OwnedCollection(zone => zone.ZoneShippingMethods,
with => with.OwnedCollection(method => method.ZoneShippingMethodRanges)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.