Я кодирую интернет-приложение MVC5 с EF6 и задаю вопрос относительно имени внешнего ключа.Entity Framework 6 foreign key
У меня есть модель под названием MapLocationList
, который имеет эти два поля:
public int mapLocationListGalleryId { get; set; }
public virtual MapLocationListGallery mapLocationListGallery { get; set; }
Когда EF создает таблицу, есть и следующие столбцы:
- mapLocationListGalleryId
- MapLocationListGallery_Id
Может кто-нибудь, пожалуйста, объясните n Почему есть два столбца для внешнего ключа MapLocationListGallery
?
Заранее спасибо
EDIT
Я изменил имя для использования в верхнем регистре М, однако дополнительный столбец еще есть.
Вот моя модель:
public class MapLocationList : IMapLocationItemWithAssets
{
[Key]
public int Id { get; set; }
[Required]
public string name { get; set; }
public bool enabled { get; set; }
[ScaffoldColumn(false)]
public string mapLocationItemType { get; set; }
[ScaffoldColumn(false)]
public string userName { get; set; }
[ScaffoldColumn(false)]
public DateTime creationDate { get; set; }
[ScaffoldColumn(false)]
public DateTime lastUpdate { get; set; }
public string thumbnailDisplayText { get; set; }
public bool parentIsMapLocation { get; set; }
public int thumbnailAssetId { get; set; }
public virtual Asset thumbnailAsset { get; set; }
public int mapLocationId { get; set; }
public virtual MapLocation mapLocation { get; set; }
public int mapLocationListGalleryId { get; set; }
public virtual MapLocationListGallery mapLocationListGallery { get; set; }
public virtual ICollection<MapLocationListItem> listItems { get; set; }
public MapLocationList()
{
creationDate = DateTime.Now;
lastUpdate = DateTime.Now;
listItems = new List<MapLocationListItem>();
}
}
Я также следующее в функции OnModelCreating
:
modelBuilder.Entity<MapLocationListGallery>()
.HasRequired(c => c.thumbnailAsset)
.WithMany()
.WillCascadeOnDelete(false);
modelBuilder.Entity<MapLocationList>()
.HasRequired(c => c.thumbnailAsset)
.WithMany()
.WillCascadeOnDelete(false);
modelBuilder.Entity<MapLocationList>()
.HasRequired(c => c.mapLocationListGallery)
.WithMany()
.WillCascadeOnDelete(false);
modelBuilder.Entity<MapLocationListItem>()
.HasRequired(c => c.thumbnailAsset)
.WithMany()
.WillCascadeOnDelete(false);
Я добавил дополнительную информацию в свой пост. – user3736648