Skip to content

Commit 5bf95af

Browse files
committed
Added migrations to EF project. Changed Default db name.
1 parent 936df5a commit 5bf95af

File tree

30 files changed

+115
-77
lines changed

30 files changed

+115
-77
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Data.Entity;
2+
using Abp.Domain.Entities;
3+
using Abp.EntityFramework;
4+
5+
namespace MySpaProject.EntityFramework
6+
{
7+
public class MySpaProjectDbContext : AbpDbContext
8+
{
9+
//TODO: Define an IDbSet for each Entity...
10+
11+
public virtual IDbSet<User> Users { get; set; } //Example
12+
13+
/* NOTE:
14+
* Setting "Default" to base class helps us when working migration commands on Package Manager Console.
15+
* But it may cause problems when working Migrate.exe of EF. If you will apply migrations on command line, do not
16+
* pass connection string name to base classes. ABP works either way.
17+
*/
18+
public MySpaProjectDbContext()
19+
: base("Default")
20+
{
21+
22+
}
23+
24+
/* NOTE:
25+
* This constructor is used by ABP to pass connection string defined in MySpaProjectDataModule.PreInitialize.
26+
* Notice that, actually you will not directly create an instance of MySpaProjectDbContext since ABP automatically handles it.
27+
*/
28+
public MySpaProjectDbContext(string nameOrConnectionString)
29+
{
30+
31+
}
32+
}
33+
34+
public class User : Entity
35+
{
36+
public string Name { get; set; }
37+
38+
public string Password { get; set; }
39+
}
40+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace MySpaProject.Migrations
2+
{
3+
using System;
4+
using System.Data.Entity;
5+
using System.Data.Entity.Migrations;
6+
using System.Linq;
7+
8+
internal sealed class Configuration : DbMigrationsConfiguration<MySpaProject.EntityFramework.MySpaProjectDbContext>
9+
{
10+
public Configuration()
11+
{
12+
AutomaticMigrationsEnabled = false;
13+
ContextKey = "MySpaProject";
14+
}
15+
16+
protected override void Seed(MySpaProject.EntityFramework.MySpaProjectDbContext context)
17+
{
18+
// This method will be called every time after migrating to the latest version.
19+
// You can add any seed data here...
20+
}
21+
}
22+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<OutputType>Library</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>MySpaProject</RootNamespace>
11-
<AssemblyName>MySpaProject.Infrastructure.EntityFramework</AssemblyName>
11+
<AssemblyName>MySpaProject.EntityFramework</AssemblyName>
1212
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
</PropertyGroup>
@@ -77,6 +77,7 @@
7777
<ItemGroup>
7878
<Compile Include="EntityFramework\MySpaProjectDbContext.cs" />
7979
<Compile Include="EntityFramework\Repositories\MySpaProjectRepositoryBase.cs" />
80+
<Compile Include="Migrations\Configuration.cs" />
8081
<Compile Include="MySpaProjectDataModule.cs" />
8182
<Compile Include="Properties\AssemblyInfo.cs" />
8283
</ItemGroup>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ namespace MySpaProject
77
[DependsOn(typeof(AbpEntityFrameworkModule), typeof(MySpaProjectCoreModule))]
88
public class MySpaProjectDataModule : AbpModule
99
{
10+
public override void PreInitialize()
11+
{
12+
Configuration.DefaultNameOrConnectionString = "Default";
13+
}
14+
1015
public override void Initialize()
1116
{
1217
IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
// General Information about an assembly is controlled through the following
66
// set of attributes. Change these attribute values to modify the information
77
// associated with an assembly.
8-
[assembly: AssemblyTitle("MySpaProject.Infrastructure.EntityFramework")]
8+
[assembly: AssemblyTitle("MySpaProject.EntityFramework")]
99
[assembly: AssemblyDescription("")]
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("")]
12-
[assembly: AssemblyProduct("MySpaProject.Infrastructure.EntityFramework")]
12+
[assembly: AssemblyProduct("MySpaProject.EntityFramework")]
1313
[assembly: AssemblyCopyright("Copyright © 2014")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]

Templates/All-In-One-Template/MySpaProject/MySpaProject.Infrastructure.EntityFramework/EntityFramework/MySpaProjectDbContext.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)