Add project files.

This commit is contained in:
2019-11-10 20:26:59 +01:00
parent 39dc8d2cc9
commit 387bb252d1
23 changed files with 889 additions and 0 deletions

View File

@ -0,0 +1,32 @@
namespace CodeFirstExistingDatabase
{
using System;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
public partial class PlutoContext : DbContext
{
public PlutoContext()
: base("name=PlutoContext")
{
}
public virtual DbSet<Author> Authors { get; set; }
public virtual DbSet<Course> Courses { get; set; }
public virtual DbSet<Tag> Tags { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Author>()
.HasMany(e => e.Courses)
.WithOptional(e => e.Author)
.HasForeignKey(e => e.Author_Id);
modelBuilder.Entity<Course>()
.HasMany(e => e.Tags)
.WithMany(e => e.Courses)
.Map(m => m.ToTable("TagCourses").MapLeftKey("Course_Id"));
}
}
}