33 lines
967 B
C#
33 lines
967 B
C#
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"));
|
|
}
|
|
}
|
|
}
|