Many Relationship to Many Entity Framework Code First Composite Primary Keys Repeated Column

1

In my application I have two entities with a many-to-many relationship, namely Activity and Skill :

EF(CodeFirst)generatesthejointableforme,butitisconflictingifIcreatethemappingathandinOnModelCreatingbecauseIhavethesamecolumn(CLIENT_ID)inbothtablesandIcannotgetCLIENTIDfromanyofthem).IfIletitgeneratewithoutmapping,itcreatesthecolumnCID_IDtwice(withdifferentnames).

IsthereanywaytosetuptheSkill_Activitytablewithouthavingtocreatetheentityandrelationshipsathand?

Models:

publicclassAtividade{publicAtividade(){Skills=newList<Skill>();}publicintId{get;set;}publicstringCustomerId{get;set;}publicvirtualClienteCliente{get;set;}publicvirtualICollection<Skill>Skills{get;set;}}publicclassSkill{publicSkill(){Activities=newList<Atividade>();}publicintSkillId{get;set;}publicstringCustomerId{get;set;}publicstringName{get;set;}publicstringDescription{get;set;}publicintScore{get;set;}publicvirtualClienteCustomer{get;set;}publicvirtualICollection<Atividade>Activities{get;set;}}

APIFluentCode

modelBuilder.Entity<Skill>().HasMany(t=>t.Activities).WithMany(t=>t.Skills).Map(m=>{m.ToTable("SKILL_ATIVIDADE");
                m.MapLeftKey("SkillId", "CustomerId");
                m.MapRightKey("Id", "CustomerId");
            });

This code does not work because I repeat the property in both entities, if I change the name of the property should work, but then I will have the same column with different names ...

    
asked by anonymous 16.02.2017 / 11:58

0 answers