Bonjour,
Je fais le mapping suivant et j'obtiens l'erreur :
L'erreur retournée est la suivante :
Message : One or more validation errors were detected during model generation:
System.Data.Edm.EdmAssociationConstraint: : The number of properties in the Dependent and Principal Roles in a relationship constraint must be identical.
Source : EntityFramework
StackTrace : à System.Data.Entity.ModelConfiguration.Edm.EdmModelExtensions.ValidateAndSerializeCsdl(EdmModel model, XmlWriter writer)
à System.Data.Entity.ModelConfiguration.Edm.EdmModelExtensions.ValidateCsdl(EdmModel model)
à System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
à System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
à System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
à System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
à System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
à System.Data.Entity.Internal.InternalContext.Initialize()
à System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
à System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
à System.Data.Entity.Internal.Linq.InternalSet`1.Include(String path)
à System.Data.Entity.Infrastructure.DbQuery`1.Include(String path)
à System.Data.Entity.DbExtensions.Include[T](IQueryable`1 source, String path)sql ==>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 public class Category { public long NumCategory { get; set; } public string NumFactory { get; set; } public virtual ICollection<Product> Products { get; set; } } public class Product { public Guid Numero { get; set; } public virtual Category Category { get; set; } public long NumCategory { get; set; } }
Sachant que Category à une clé composée (numCategory et numFactory)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 CREATE TABLE `CATEGORY` ( `NUM_CATEGORY` int(11) NOT NULL , `NUM_FACTORY` varchar(11) NOT NULL , `lIB_CATEGORY` varchar(100) DEFAULT NULL , PRIMARY KEY (`NUM_CATEGORY`,`NUM_FACTORY`), ) CREATE TABLE `PRODUCT` ( `NUMERO` char(36) NOT NULL, `LIBELLE` varchar(60) DEFAULT NULL, `NUM_CATEGORY` int(11) NOT NULL, PRIMARY KEY (`NUMERO`), KEY `FK_PRODUCT_CATEGORY` (`FIC_COURRIER`), CONSTRAINT `FK_PRODUCT_CATEGORY` FOREIGN KEY (`NUM_CATEGORY`) REFERENCES `CATEGORY` (`NUM_CATEGORY`) ON DELETE NO ACTION ON UPDATE NO ACTION )
Mapping ==>
ça fonctionne si j'enlève la clé composée (numCategory et numFactory) sur la table Category
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 internal partial class ProductMapping : EntityTypeConfiguration<Product> { public ProductMapping() { this.HasKey(K => new { K.Numero }); this.ToTable("PRODUCT"); this.Property(t => t.Numero).HasColumnName("NUMERO").HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); this.Property(t => t.NumCategory).HasColumnName("NUM_CATEGORY").IsRequired(); this.HasRequired(t => t.Category).WithMany(t => t.Products).HasForeignKey(t => t.NumCategory); } } internal partial class CategoryMapping : EntityTypeConfiguration<Category> { public CategoryMapping() { this.HasKey(t => new {t.NumCategory, t.NumFactory}); this.ToTable("CATEGORY"); this.Property(t => t.NumFactory).HasColumnName("NUM_FACTORY");//.IsRequired(); this.Property(t => t.NumCategory).HasColumnName("NUM_CATEGORY").HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); } }
Merci pour tout aide
Partager