From 6120168c86daa2c712dc4a9a5ce44da34ed50d5b Mon Sep 17 00:00:00 2001 From: AndriySvyryd Date: Wed, 10 Dec 2014 14:16:20 -0800 Subject: [PATCH] Reacting to the new EF relationship discovery convention --- src/MusicStore/Models/MusicStoreContext.cs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/MusicStore/Models/MusicStoreContext.cs b/src/MusicStore/Models/MusicStoreContext.cs index 63e5e05f67..41cda5cc54 100644 --- a/src/MusicStore/Models/MusicStoreContext.cs +++ b/src/MusicStore/Models/MusicStoreContext.cs @@ -29,13 +29,21 @@ namespace MusicStore.Models builder.Entity().Property(a => a.ArtistId).GenerateValueOnAdd(generateValue: false); builder.Entity().Property(g => g.GenreId).GenerateValueOnAdd(generateValue: false); - // TODO: Remove this once convention-based relations work again - builder.Entity().ManyToOne(a => a.Artist); - builder.Entity().ManyToOne(a => a.Genre, g => g.Albums); - builder.Entity().OneToMany(o => o.OrderDetails); - //Deleting an album fails with this relation - //builder.Entity().OneToMany(a => a.OrderDetails, od => od.Album); + builder.Entity().Ignore(a => a.OrderDetails); + builder.Entity().Ignore(od => od.Album); + + var orderDetails = builder.Model.GetEntityType(typeof(OrderDetail)); + var albumNavigation = orderDetails.TryGetNavigation("Album"); + if (albumNavigation != null) + { + orderDetails.RemoveNavigation(albumNavigation); + + var album = builder.Model.GetEntityType(typeof(Album)); + album.RemoveNavigation(album.GetNavigation("OrderDetails")); + + orderDetails.RemoveForeignKey(albumNavigation.ForeignKey); + } base.OnModelCreating(builder); }