Is the following good design for doing entity framework code first? What am I missing for a production system? I haven't included all my code, just a snapshot...
My application, doesn't update the database; it just reads it.
public class Document
{
[Key, ScaffoldColumn(false)]
public Int32 DocumentID { get; set; }
[ScaffoldColumn(false)]
public Boolean? Status { get; set; }
[Display(Name = "Document Text"), DataType(DataType.MultilineText)]
public String DocumentText { get; set; }
[ScaffoldColumn(false), DataType(DataType.Url)]
public String DocumentFolderPath { get; set; }
[ScaffoldColumn(false), DataType(DataType.Url)]
public String DocumentJSONPath { get; set; }
[ForeignKey("DocumentID")]
public virtual DocumentMetadata Metadata { get; set; }
[ForeignKey("DocumentID")]
public virtual ICollection<Page> Pages { get; set; }
}
public class Page
{
[Key, ScaffoldColumn(false)]
public Int32 PageID { get; set; }
[Required, Display(Name = "Page"), DataType(DataType.Text)]
public Int32 PageNumber { get; set; }
[Required, ScaffoldColumn(false)]
public Int32 DocumentID { get; set; }
[ScaffoldColumn(false), DataType(DataType.ImageUrl)]
public String ImagePath { get; set; }
[Required, Display(Name = "Page Text"), DataType(DataType.MultilineText)]
public String PageText { get; set; }
[NotMapped]
public String HighlightedText { get; set; }
[ForeignKey("PageID")]
public virtual ICollection<Word> Words { get; set; }
}
public class ArchiveDatabaseInitializer : DropCreateDatabaseIfModelChanges<ArchiveContext>
{
protected override void Seed(ArchiveContext context)
{
try
{
GetDocuments().ForEach(d => context.Documents.Add(d));
GetDocumentMetatdata().ForEach(d => context.DocMetadata.Add(d));
GetPages().ForEach(d => context.Pages.Add(d));
GetWords().ForEach(d => context.Words.Add(d));
context.SaveChanges();
}
catch (Exception ex)
{
throw ex;
}
}
private static List<Document> GetDocuments()
{
var documents = new List<Document> {
new Document
{
DocumentID = 1,
DocumentFolderPath = @"Doc1",
DocumentJSONPath = @"Doc1.json",
Status = true
},
new Document
{
DocumentID = 2,
DocumentFolderPath = @"Doc2",
DocumentJSONPath = @"Doc2.json",
Status = true
}
};
return documents;
}
public class ArchiveContext : DbContext
{
public ArchiveContext()
: base("archiveDB")
{
}
public DbSet<Document> Documents { get; set; }
public DbSet<DocumentMetadata> DocMetadata { get; set; }
public DbSet<Page> Pages { get; set; }
public DbSet<Word> Words { get; set; }
}
ICollection<Page>
navigation property can have a FK attribute AND work. But I could be wrong. It just... looks weird to me. I've favorited this question, I'll get back to it when I have a chance :) \$\endgroup\$