Önceden oluşturulmuş iki tablom var. Document
ve DocumentStyle
. DocumentID
sütunu aracılığıyla bire bir ilişki var. Ancak, Document
tablosunda Id
ve DocumentStyle
tablosunda DocumentId
olarak adlandırılır. BuTek bir ilişki, farklı anahtar sütun adı, Varlık Çerçevesi, Kod İlk yaklaşım
> Document DocumentStyle
> |----------| |----------------|
> |Id - Key |<------>|DocumentId- key |
> |Name-VChar| |Color -VChar|
> |Desc-VChar| |Font VChar |
> |----------| |----------------|
gibi
Ben zengin geçerli değil tip 'KII.Models.Document' üzerinde mülkiyet 'DocumentStyle' üzerinde
VS
yılında ForeignKeyAttribute aşağıdaki hatayı alıyorum . 'DocumentId' yabancı anahtar adı 'KII.Models.Document' bağımlı türünde bulunamadı oldu. Adı değeri, yabancı anahtar özellik adlarının virgülle ayrılmış bir listesi olmalıdır.
Bu belge modeli sınıf için kod parçasıdır
[ForeignKey("DocumentId")] public
DocumentStyle DocumentStyle { get;set; }
DÜZENLEME:
Bu benim sınıfların kodudur.
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; } }
Büyük bağlıdır
eğer:
Document
bağımlı varlık veyaeğer. Yanlış anladım. Bu hile yaptı. Bu hatayı geçtim. Ancak şimdi bunu anlıyorum. "Document_DocumentStyle" ilişkisinde "Multiplicity, Role" Document_DocumentStyle_Source "ilişkisinde geçerli değildir. Bağımlı Rol, anahtar özelliklerine başvurduğundan, Bağımlı Rolün çokluğunun üst sınırının 1" – Omar
Öğelerinizi veya akıcı eşlemenizi göstermesi gerekir. Bu mümkün olmadığında isteğe bağlı bir tarafı tanımlamaya çalışıyor gibi görünüyor. –
ForeignKey özniteliği, yalnızca yabancı anahtarın tanımlandığı bir ilişkide kullanılmalıdır. Sanırım 'Document' modelinizde esastır, bu yüzden 'DocumentStyle' özelliğinden özniteliği kaldırın. –