bonjour a tous
je developpe un application asp.net mvc
j'ai deux tables(Gamme et catalogues) avec une relation many to many

la classe gamme
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
23
24
25
26
27
28
29
 
  [Bind(Exclude = "Gam_Code")]
   public class TR_Gamme_Montage
    {
        [ScaffoldColumn(true)]
        [DisplayName("Code")]
        [Key]
        public int Gam_Code { get; set; }
 
        [DisplayName("Article")]
        [UIHint("DropDownList")]
        public int Art_Code { get; set; }
 
        [DisplayName("Modele")]
        [UIHint("DropDownList")]
        public int Mod_Code { get; set; }
 
        [DisplayName("Saison")]
        [UIHint("DropDownList")]
        public int Sai_Code { get; set; }
 
        public virtual TR_Article Article { get; set; }
        public virtual TR_Modele Modele { get; set; }
        public virtual TR_Saison Saison { get; set; }
 
 
        public ICollection<TR_Catalogue_Temps> Catalogues { get; set; }
 
    }
la classe catalogues :

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
23
24
25
26
27
28
29
30
 [Bind(Exclude = "Cat_Code")]
    public class TR_Catalogue_Temps
    {
        [ScaffoldColumn(true)]
        [DisplayName("Code")]
        [Key]
        public int Cat_Code { get; set; }
 
        [DisplayName("Operation")]
        [UIHint("DropDownList")]
        public int Ope_Code { get; set; }
 
        [DisplayName("Machine")]
        [UIHint("DropDownList")]
        public int Mac_Code { get; set; }
 
        [DisplayName("Article")]
        [UIHint("DropDownList")]
        public int Art_Code { get; set; }
 
        [Required]
        [DisplayName("Temps prévus")]
        [DataType(DataType.Duration)]
        public decimal Cat_Temps_Prevus { get; set; }
 
        public virtual TR_Operation Operation { get; set; }
        public virtual TR_Machine Machine { get; set; }
        public virtual TR_Article Article { get; set; }
 
        public ICollection<TR_Gamme_Montage> Gammes { get; set; }

et la classe context :
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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
public class dbContext : DbContext
    {
        public DbSet<TR_Gamme_Montage> Gammes { get; set; }
 
        public DbSet<TR_Machine> Machine { get; set; }
        public DbSet<TR_Operation> Operation { get; set; }
        public DbSet<TR_Article> Article { get; set; }
        public DbSet<TR_Catalogue_Temps> Catalogues { get; set; }
        public DbSet<TR_Saison> Saison { get; set; }
        public DbSet<TR_Modele> Modele { get; set; } 
 
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
              modelBuilder.Entity<TR_Element>().
              HasMany(c => c.Modele).
              WithMany(p => p.Elements).
 
              Map(
               m =>
               {
                   m.MapLeftKey("Ele_Code");
                   m.MapRightKey("Mod_Code");
                   m.ToTable("Tr_Ligne_Element");
               });
              modelBuilder.Entity<TR_Catalogue_Temps>().
                HasMany(c => c.Gammes).
                WithMany(p => p.Catalogues).
 
                Map(
                 m =>
                 {
                     m.MapLeftKey("Cat_Code");
                     m.MapRightKey("Gam_Code");
                     m.ToTable("Tr_Ligne_Gammes");
                 });
        }
voici l'interface d'ajout

Nom : MANY to many .png
Affichages : 83
Taille : 15,0 Ko

comment se fait l'ajout a la base (la methode post create???)