2017-02-08 3 views
3

Mit .NET Entity Framework-Code Zuerst habe ich zwei einfache Modelle:Entity Framework ICollection erstellt interne Tabelle

public class Car 
{ 
    public int CarId { get; set; } 

    public ICollection<Location> Locations { get; set; } 
} 

public class Location 
{ 
    public int LocationId { get; set; } 

    public ICollection<Car> Cars { get; set; } 
} 

dieses eine dritte Tabelle zu tun, ist mit dem Namen erstellt: LocationCars.

Gibt es sowieso den Namen dieser generierten Tabelle anzupassen?

Vielen Dank

Antwort

1

Ja, Sie haben FluentApi verwenden, um die many-to-many-Beziehung

Vom turorial

protected override void OnModelCreating(DbModelBuilder modelBuilder) 
{ 
    modelBuilder.Entity<Car>() 
       .HasMany(c => c.Locations) 
       .WithMany(l => l.Cars) 
       .Map(cl => 
         { 
         cl.MapLeftKey("CarId"); 
         cl.MapRightKey("LocationId"); 
         cl.ToTable("YOUR_TABLE_NAME"); 
         }); 
} 
0

Sie Handbuch many-to-many-Mapping erstellen anpassen :

modelBuilder.Entity<Car>() 
    .HasMany(c => c.Locations) 
    .WithMany() 
    .Map(l => l.MapLeftKey("CarId").MapRightKey("LocationId").ToTable("TableNameHere")); 
Verwandte Themen