我正在尝试仅在“很多”方面配置导航的一对多关系,但似乎无法让EF生成正确的列名。
以下是相关架构:
QuoteItem
Id INT PRIMARY KEY
QuoteItemFiles
Id INT PRIMARY KEY
QuoteItemId INT NOT NULL
FileId INT NOT NULL
Files
FileID INT PRIMARY KEY (legacy naming convention)
模特:
public class QuoteItem
{
public int Id { get; set; }
public ICollection<QuoteItemFile> Attachments { get; set; }
}
public class QuoteItemFile
{
public int Id { get; set; }
public File File { get; set; }
public QuoteItem QuoteItem { get; set; }
}
public class File
{
public int FileID { get; set; }
}
我正在配置这样的关系:
public class QuoteItemMap()
{
HasMany(x => x.Attachments)
.WithRequired(x => x.QuoteItem)
.Map(x => x.MapKey("QuoteItemId"))
.WillCascadeOnDelete(true);
}
public QuoteItemFileMap()
{
HasRequired(x => x.QuoteItem)
.WithMany(x => x.Attachments)
.Map(x => x.MapKey("QuoteItemId"))
.WillCascadeOnDelete(true);
HasRequired(x => x.File)
.WithMany()
.Map(x => x.MapKey("FileId")) <-- This isn't working
.WillCascadeOnDelete(true);
}
当我尝试访问QuoteItem.Attachments时,我得到“无效的列名'File_FileID'。”
为什么不遵守我的MapKey("FileId")
指令?