How to indicate to entity framework code first a correct mapping

pescasat

New Member
I've got three tables and I need a relationship between tables cllaed Test and Objective (1 to many). I create a third table to maintain the relationships. But EntityFramework Code first in ASP.NET MVC is creating a wrong mapping. Check this:\[code\][Table("Objective")]public class Objective{ [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int ObjectiveId { get; set; } ...}[Table("Test")]public class Test{ [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int TestId { get; set; } ... //public ICollection<Objective> Objectives { get; set; }}[Table("TestToObjectives")]public class TestToObjectives{ [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int TestToObjectivesId { get; set; } public Test Test { get; set; } public ICollection<Objective> Objectives { get; set; }}public class ContosoDb : DbContext{ public ContosoDb() : base("name=DefaultConnection") {} public DbSet<Test> Tests { get; set; } public DbSet<Objective> Objectives { get; set; } public DbSet<TestToObjectives> TestToObjectives { get; set; }}\[/code\]This is the result of my tables after a enter the command \[code\]Update-Database -Verbose\[/code\]
Jl48D.png
How can I indicate to Entity which I'm trying to do?
 
Back
Top