我正在尝试仅在“多”端配置与导航的一对多关系,但似乎无法让 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")
指令?