Aspnet.Data 1.0.7

dotnet add package Aspnet.Data --version 1.0.7
NuGet\Install-Package Aspnet.Data -Version 1.0.7
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Aspnet.Data" Version="1.0.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Aspnet.Data --version 1.0.7
#r "nuget: Aspnet.Data, 1.0.7"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Aspnet.Data as a Cake Addin
#addin nuget:?package=Aspnet.Data&version=1.0.7

// Install Aspnet.Data as a Cake Tool
#tool nuget:?package=Aspnet.Data&version=1.0.7

UnityConfig.cs

public static void RegisterTypes(IUnityContainer container)
{
    // NOTE: To load from web.config uncomment the line below.
    // Make sure to add a Unity.Configuration to the using statements.
    // container.LoadConfiguration();

    // TODO: Register your type's mappings here.
    container.RegisterType<ICategoryRepository, CategoryRepository>();
    container.RegisterType<IOrderRepository, OrderRepository>();
    container.RegisterType<ICustomerRepository, CustomerRepository>();

    container.RegisterType<IUnitOfWork, UnitOfWork<NORTHWNDEntities>>().RegisterInstance(container);
}

HomeController.cs

public class BaseController : Controller
{
    private IUnitOfWork _uow;

    public BaseController(IUnitOfWork uow)
    {
        _uow = uow;
    }

    public void Commit()
    {
        _uow.Commit();
        _uow.Dispose();
    }
}

public class HomeController : BaseController
{
    private IOrderRepository _ordersRepo;
    private ICustomerRepository _custRepo;
    private ICategoryRepository _categRepo;

    public HomeController(IUnitOfWork uow) : base(uow)
    {
        _ordersRepo = uow.Get<IOrderRepository>();
        _custRepo = uow.Get<ICustomerRepository>();
        _categRepo = uow.Get<ICategoryRepository>();
    }
	
	
	public void Demo()
	{
		//add
		_categRepo.Add(new Categories { CategoryName = "test", Description = "none" });

		//get
		var cust = _custRepo.Get(c => c.CustomerId == "ALFKI");

		//update
		cust.Address = "Test address";
		_custRepo.Update(cust);

		//delete
		var categ = _categRepo.Get(c => c.CategoryId == 2);
		_categRepo.Remove(categ);

		this.Commit();
	}
	
	
	public void Demo2()
	{
		var categoreis = _categRepo.GetCategories();

		var orders = _ordersRepo.GetOrders();

		var cusomters = _custRepo.GetCustomers();

		var customer = _custRepo.GetCustomer("ALFKI");
	}		
}

Repositories

public interface ICategoryRepository : IDataRepository<Categories>
{
    IEnumerable<Categories> GetCategories();
}
public class CategoryRepository : DataRepository<Categories>, ICategoryRepository
{
    public CategoryRepository(DbContext dbContext) : base(dbContext)
    {
    }

    public IEnumerable<Categories> GetCategories()
    {
        return base.SqlQuery<Categories>("select * from categories").ToList();
    }
}

public interface IOrderRepository : IDataRepository<Orders>
{
    IEnumerable<Orders> GetOrders();
}
public class OrderRepository : DataRepository<Orders>, IOrderRepository
{
    public OrderRepository(DbContext dbContext) : base(dbContext)
    {
    }

    public IEnumerable<Orders> GetOrders()
    {
        return base.SqlQuery<Orders>("select * from Orders").ToList();
    }
}

public interface ICustomerRepository : IDataRepository<Customers>
{
    IEnumerable<Customers> GetCustomers();
    Customers GetCustomer(string customerId);
}
public class CustomerRepository : DataRepository<Customers>, ICustomerRepository
{
    public CustomerRepository(DbContext dbContext) : base(dbContext)
    {
    }

    public Customers GetCustomer(string customerId)
    {
        var (cust,outParams) = base.SqlQuery2<Customers>("spGetCustomersById", true, new { CustomerId = customerId }, new { TotalRows = 0 });

        var count = outParams.Get<int>("TotalRows");

        return cust.FirstOrDefault();
    }

    public IEnumerable<Customers> GetCustomers()
    {
        return base.SqlQuery<Customers>("spGetCustomers",true).ToList();
    }
}	

SQL scripts sample

//
create proc spGetCustomersById
@CustomerId varchar(20),
@TotalRows int out
as
begin
	select * from Customers where CustomerID = @CustomerId
	select @TotalRows = count(1) from Customers where CustomerID = @CustomerId
end

//
create proc spGetCustomers
as
begin
	select * from Customers
end	
Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.7 1,016 8/6/2018
1.0.6 848 8/3/2018