简体   繁体   中英

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.

The correct mapping in your case looks like this:

context.UpdateGraph(shippingZone, 
    map => map.OwnedCollection(zone => zone.ZoneShippingMethods, 
        with => with.OwnedCollection(method => method.ZoneShippingMethodRanges)));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM