Add project files.
This commit is contained in:
32
CodeFirstExistingDatabase/PlutoContext.cs
Normal file
32
CodeFirstExistingDatabase/PlutoContext.cs
Normal 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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user