ASP.NET Core and SQL Lite Web Sample Application

asp.net-core asp.net-core-1.0 entity-framework-core sqlite

Question

I actually searching for a simple asp.net core (1.0) web application sample using sql lite as back end.

Can someone point me in the right direction

Basically I need to just create a contact me form in asp.net core and have a sql lite as back end.

Thanks in Advance for the replies.

(PS: asp.net core sample, one that will actually work in vs 2015 and will not give... The dependency does not support framework .NETCoreApp,Version=v1.0.)

1
1
10/22/2016 4:29:41 PM

Popular Answer

Basic steps to use SQLlite in ASP.NET core 1.0 are as follows-

1) Create new ASP.NET core application

enter image description here

2) In project.json, add these packages-

"Microsoft.EntityFrameworkCore": "1.0.1",
"Microsoft.EntityFrameworkCore.SQlite": "1.0.1"

3) Create DatabaseContext.cs in your project-

using Microsoft.EntityFrameworkCore;

namespace AspNetCore_SQLlite
{
    public class DatabaseContext : DbContext
    {
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlite("Filename:myTestDB.db");
        }
    }

4) In ConfigureServices method of startup.cs, add DbContext service-

services.AddEntityFrameworkSqlite().AddDbContext<DatabaseContext>();

5) In Startup method of startup.cs, create DB like this-

using (var db = new DatabaseContext())
{
    db.Database.EnsureCreated();
}

For more information, you can refer these articles-

https://docs.efproject.net/en/latest/platforms/netcore/new-db-sqlite.html

https://docs.efproject.net/en/latest/providers/sqlite/

2
10/22/2016 4:27:48 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow