MobileApped.Core.Persistence.SqlServer 2.0.1

EFCore persistence library, abstracting and simplifying dbcontext sql server database integration

Install-Package MobileApped.Core.Persistence.SqlServer -Version 2.0.1
dotnet add package MobileApped.Core.Persistence.SqlServer --version 2.0.1
<PackageReference Include="MobileApped.Core.Persistence.SqlServer" Version="2.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MobileApped.Core.Persistence.SqlServer --version 2.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Getting started

Create a AppSettings.json

{
    "ConnectionStrings": {
        "TestConnection" : "database connection string"
    }
}

Create an Entity class

public class Person {
    [Key] public int ID { get; set; }
}

Create a DbContext

public class PersonContext : DbContext {
    public PersonContext(DbContextOptions options) : base(options){} // This constructor is required when using this library

    public DbSet<Person> People { get; set; }
}

Register a DbContext with the ServiceCollection

IConfiguration configuration = new ConfigurationBuilder()
    .AddJsonFile("AppSettings.json")
    .Build();
IServiceCollection services = new ServiceCollection();
services.AddSqlServerDataContext<PersonContext>(configuration, "TestConnection");

Consume the DataContext

public class HomeController : Controller {
    private IDataContext<PersonContext> context;
    public HomeController(IDataContext<PersonContext> context)
    { 
        this.context = context;
    }

    [HttpGet("api/people")]
    public IActionResult GetPeople()
    {
        var people = context.UsingContext(d => d.People.ToList());
        return Json(people);
    }
}

Getting started

Create a AppSettings.json

{
    "ConnectionStrings": {
        "TestConnection" : "database connection string"
    }
}

Create an Entity class

public class Person {
    [Key] public int ID { get; set; }
}

Create a DbContext

public class PersonContext : DbContext {
    public PersonContext(DbContextOptions options) : base(options){} // This constructor is required when using this library

    public DbSet<Person> People { get; set; }
}

Register a DbContext with the ServiceCollection

IConfiguration configuration = new ConfigurationBuilder()
    .AddJsonFile("AppSettings.json")
    .Build();
IServiceCollection services = new ServiceCollection();
services.AddSqlServerDataContext<PersonContext>(configuration, "TestConnection");

Consume the DataContext

public class HomeController : Controller {
    private IDataContext<PersonContext> context;
    public HomeController(IDataContext<PersonContext> context)
    { 
        this.context = context;
    }

    [HttpGet("api/people")]
    public IActionResult GetPeople()
    {
        var people = context.UsingContext(d => d.People.ToList());
        return Json(people);
    }
}

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.0.1 240 3/16/2018