using System.Data.Common;
using Abp.Zero.EntityFramework;
using MyCompany.MyProject.Authorization.Roles;
using MyCompany.MyProject.MultiTenancy;
using MyCompany.MyProject.Users;
using System.Data.Entity;
using MyCompany.MyProject.Entities;
namespace MyCompany.MyProject.EntityFramework
{
public class MyProjectDbContext : AbpZeroDbContext<Tenant, Role, User>
{
//TODO: Define an IDbSet for your Entities...
public virtual IDbSet<Player> Players { set; get; }
public virtual IDbSet<Map> Maps { set; get; }
/* NOTE:
* Setting "Default" to base class helps us when working migration commands on Package Manager Console.
* But it may cause problems when working Migrate.exe of EF. If you will apply migrations on command line, do not
* pass connection string name to base classes. ABP works either way.
*/
public MyProjectDbContext()
: base("Default")
{
}
/* NOTE:
* This constructor is used by ABP to pass connection string defined in MyProjectDataModule.PreInitialize.
* Notice that, actually you will not directly create an instance of MyProjectDbContext since ABP automatically handles it.
*/
public MyProjectDbContext(string nameOrConnectionString)
: base(nameOrConnectionString)
{
}
//This constructor is used in tests
public MyProjectDbContext(DbConnection connection)
: base(connection, true)
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Player>().HasRequired(p => p.Map);
}
}
}
/* NOTE:
* Setting "Default" to base class helps us when working migration commands on Package Manager Console.
* But it may cause problems when working Migrate.exe of EF. If you will apply migrations on command line, do not
* pass connection string name to base classes. ABP works either way.
*/
public MyProjectDbContext()
: base("Default")
{
}
我們在開頭註解 //TODO: Define an IDbSet for your Entities... 下方增加我們要用實體建立資料表的Code
//TODO: Define an IDbSet for your Entities...
public virtual IDbSet<Player> Players { set; get; }
public virtual IDbSet<Map> Maps { set; get; }