I have two tables:
- Documents (Id, DocumentTypeId, Title, Details)
- DocumentTypes (Id, Name, Description).
DocumentTypeId is a foreign key that references a DocumentTypes table. That is, all documents can have the type assigned to them.
I have two classes:
public class Document { public string Id { get; set; } public string Title { get; set; } public DocumentType DocumentType { get; set; } }
and
public class DocumentType { public string Id { get; set; } public string Name { get; set; } public string Description { get; set; } }
and ive got the configuration
internal class DocumentsConfiguration : EntityTypeConfiguration<Document> { public DocumentsConfiguration() { ToTable("Documents"); HasKey(document => document.Id); Property(document => document.Id).HasColumnName("Id"); HasRequired(document => document.DocumentType);
And it does not work. I get this error message:
Invalid column name 'DocumentType_Id'
If I rename the fk column to DocumentType_Id, then Im will get this error message:
Invalid column name 'DocumentTypeId'
My question is how to establish a one-to-many relationship? That is, Id like to have many documents with different types of documents.
source share