Skip to content

Auto generate POCO classes at runtime for use in .NET Framework & .NET Core applications. No DbContext required; classes are created from database schema.

License

Notifications You must be signed in to change notification settings

AutoPocoIO/AutoPocoIO

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AutoPocoIO

Official Site preview version License LGPLv3 Build status Build status codecov

Overview

Auto generate Entity Framework POCO classes at runtime to build dynamic type ASP.NET applications. Classes are generated from your database's current schema. Supports CRUD and execute operations on SQL, mysql, & Oracle tables, views, and stored procedures. Requests are logged automatically, so there is no need to write custom logging. Grant or restrict column-level access using the Role Based authorization service.

Or use AutoPoco to expose your database via a REST Web API. Use OData to query and filter your requests. Interact with the Web API via Swagger.

Installation

dotnet add package AutoPocoIO

Then install the provider package corresponding to your target database(s).

dotnet add package AutoPocoIO.MsSql

Usage

Inject Operation type into controller

public SampleController(ITableOperations tableOps, ILoggingService loggingService)
{
    _loggingService = loggingService;
    _tableOps = tableOps;
}

Create and load an object from a Database Table or View:

var foo = tableOp.GetAll("AdventureWorksDB", "Customer");
var bar = tableOp.GetById("AdventureWorksDB", "Customer", 42);
var foo1 = viewOp.GetAll("AdventureworksDB", "vw_Customer");

Call a Stored Procedure, with or without parameters:

var foo = storedProcedureOp.ExecuteNoParameters("AdventureWorksDB", "sproc_Customers");
var bar = storedProcedureOp.Execute("AdventureWorksDB", "sproc_customer", "'id': 1");

Automatically log the request by passing it to the operation:

tableOp.CreateNewRow("AdventureWorksDB", "Customer", rowObject, loggingService);
tableOp.UpdateRow("AdventureWorksDB", "Customer", rowObject, loggingService);

Setup

ASP.NET

After installation in ASP.NET, update your existing OWIN Startup file with the following lines of code to set.

using AutoPocoIO.Extensions;
using Microsoft.Extensions.DependencyInjection;
using System.Reflection;
public void Configuration(IAppBuilder app)
{
    ServiceCollection services = new ServiceCollection();
    services.AddAutoPoco()
            .RegisterControllers(Assembly.GetExecutingAssembly())
            .ConfigureSqlServerApplicationDatabase("<connection string>")
            .WithSqlServerResources();

    app.UseAutoPoco(services);
}

ASP.NET Core

In the ConfigureServices method of Startup.cs, register the AutoPoco, set up application database, and register resource providers.

using AutoPocoIO.Extensions
services.AddAutoPoco()
        .ConfigureSqlServerApplicationDatabase("<connection string>")
        .WithSqlServerResources();

In the Configure method, insert middleware for logging, dashboard, and swagger api explorer

app.UseAutoPoco();

About

Auto generate POCO classes at runtime for use in .NET Framework & .NET Core applications. No DbContext required; classes are created from database schema.

Topics

Resources

License

Stars

Watchers

Forks