-
-
Notifications
You must be signed in to change notification settings - Fork 163
Usage
After cloning or downloading the sample you should be able to run it using an In Memory database immediately. The default configuration of Entity Framework Database is "InMemoryDatabase". If you wish to use the project with a persistent database, you will need to run its Entity Framework Core migrations before you will be able to run the app, and update the ConfigureDatabases method in Startup.cs (see below).
public void ConfigureDatabases(IServiceCollection services)
{
// use in-memory database
services.AddDbContext<AspnetRunContext>(c =>
c.UseInMemoryDatabase("AspnetRunConnection")
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking));
//// use real database
//services.AddDbContext<AspnetRunContext>(c =>
// c.UseSqlServer(Configuration.GetConnectionString("AspnetRunConnection"))
// .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking));
}
-
Ensure your connection strings in
appsettings.json
point to a local SQL Server instance. -
Open a command prompt in the Web folder and execute the following commands:
dotnet restore
dotnet ef database update -c AspnetRunContext -p ../AspnetRun.Infrastructure/AspnetRun.Infrastructure.csproj -s AspnetRun.Web.csproj
Or you can direct call ef commands from Visual Studio Package Manager Console. Open Package Manager Console, set default project to AspnetRun.Infrastructure and run below command;
update-database
These commands will create aspnetrun database which include Product and Category table. You can see from AspnetRunContext.cs.
- Run the application. The first time you run the application, it will seed aspnetrun sql server database with a few data such that you should see products and categories.
If you modify-change or add new some of entities to Core project, you should run ef migrate commands in order to update your database as the same way but below commands;
add migration YourCustomEntityChanges
update-database
You can check full repository documentations, step by step development and how to build your custom scenario's on this basement in 100+ page eBook PDF from here - http://www.aspnetrun.com.