【发布时间】:2011-08-25 01:49:50
【问题描述】:
我已经创建了两个表。 Document 和 DocumentStyle。它们通过DocumentID 列具有一对一的关系。但是,在Document 表中称为Id,在DocumentStyle 表中称为DocumentId。
类似的东西
> Document DocumentStyle
> |----------| |----------------|
> |Id - Key |<------>|DocumentId- key |
> |Name-VChar| |Color -VChar|
> |Desc-VChar| |Font VChar |
> |----------| |----------------|
我在 VS 中遇到以下错误
属性上的 ForeignKeyAttribute 'DocumentStyle' 类型 “KII.Models.Document”无效。 外键名称“DocumentId”是 在依赖类型上找不到 'KII.Models.Document'。名称值 应该是一个逗号分隔的列表 外键属性名称。
这是文档模型类的部分代码
[ForeignKey("DocumentId")] public
DocumentStyle DocumentStyle { get;set; }
编辑:
这是我的课程的代码。
public class Document { [Key] public int ID { get; set; } public string Name { get; set; } public int FundId { get; set; } public int ClientId { get; set; } [ForeignKey("FundId")] public Fund Fund { get; set; } [ForeignKey("ClientId")] public Client Client { get; set; } //public ImageWrapper Logo { get; set; } [ForeignKey("ID")] public DocumentStyle DocumentStyle { get; set; } public Document() { } public Document(DocumentStyle documentStyle) { DocumentStyle = documentStyle; } } public class DocumentStyle { public DocumentStyle() { } [Key] [DisplayName("Document ID")] public int DocumentId { get; set; } [ForeignKey("DocumentId")] public Document Document { get; set; } [DisplayName("Title Foreground Color")] public string TitleForegroundColor { get; set; } [DisplayName("Title Background Color")] public string TitleBackgroundColor { get; set; } [DisplayName("Title Font Family")] public string TitleFontFamily { get; set; } [DisplayName("Title Font Size")] public string TitleFontSize { get; set; } [DisplayName("Title Font Style")] public string TitleFontStyle { get; set; } [DisplayName("Title Font Weight")] public string TitleFontWeight { get; set; } [DisplayName("Title Text Decoration")] public string TitleTextDecoration { get; set; } [DisplayName("Section Title Foreground Color")] public string SectionTitleForegroundColor { get; set; } [DisplayName("Section Title Background Color")] public string SectionTitleBackgroundColor { get; set; } [DisplayName("Section Title Font Family")] public string SectionTitleFontFamily { get; set; } [DisplayName("Section Title Font Size")] public string SectionTitleFontSize { get; set; } [DisplayName("Section Title Font Styled")] public string SectionTitleFontStyle { get; set; } [DisplayName("Section Title Font Weight")] public string SectionTitleFontWeight { get; set; } [DisplayName("Section Title Text Decoration")] public string SectionTitleTextDecoration { get; set; } [DisplayName("Paragraph Foreground Color")] public string ParagraphForegroundColor { get; set; } [DisplayName("Paragraph Background Color")] public string ParagraphBackgroundColor { get; set; } [DisplayName("Paragraph Font Family")] public string ParagraphFontFamily { get; set; } [DisplayName("Paragraph Font Size")] public string ParagraphFontSize { get; set; } [DisplayName("Paragraph Font Style")] public string ParagraphFontStyle { get; set; } [DisplayName("Paragraph Font Weight")] public string ParagraphFontWeight { get; set; } [DisplayName("Paragraph Text Decoration")] public string ParagraphTextDecoration { get; set; } [DisplayName("Logo")] public byte[] Logo { get; set; } }
【问题讨论】:
标签: c# ef-code-first entity-framework-4.1