old*_*ard 3 asp.net-mvc entity-framework asp.net-mvc-5
我希望能够使用Visual Studio 2013中的"添加 - 脚手架"为与另一个模型有许多关系的模型添加CRUD.不幸的是,脚手架视图/控制器根本不触及关系,在创建/编辑视图中不呈现SelectList.
尽管如此,脚手架适用于一对多的关系.多对多是一个未在Scaffold工具中实现的功能,还是我做错了什么?
我正在使用Fluent API.
这些是我的模型(为了便于阅读而剥离)
public class Category
{
public int Id { get; set; }
public virtual ICollection<Country> Countries { get; set; }
}
public class Country
{
public string Iso { get; set; }
public string GlobalName { get; set; }
public string LocalName { get; set; }
public virtual ICollection<Category> Categories { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这些是Fluent API配置类
public class CategoryConfiguration: EntityTypeConfiguration<Category>
{
public CategoryConfiguration()
{
HasKey(c => new { c.Id });
HasMany(c => c.Countries)
.WithMany(c => c.Categories)
.Map(m =>
{
m.ToTable("CategoryCountry_JT");
m.MapLeftKey("CategoryId");
m.MapRightKey("CountryId");
});
}
}
public class CountryConfiguration : EntityTypeConfiguration<Country>
{
public CountryConfiguration()
{
HasKey(c => new { c.Iso });
Property(c => c.GlobalName).IsRequired();
Property(c => c.LocalName).IsRequired();
}
}
Run Code Online (Sandbox Code Playgroud)
也许Join Table必须声明为真正的模型,而不是.Map(m => ...让Scaffold工作?