Description
AutoClutch is a tool for getting data. A few years ago I created a much larger much more complicated generic repository for use in the enterprise. While it worked well in .NET 3.5 and Entity Framework 4 adding on more features and extending it to work with the newest versions of .NET and Entity Framework became a laborious task. I decided to create a simple repository with the knowledge I had. The idea was to target the repository for the most current versions of .NET and Entity Framework. With no restrictions on backwards compatibility the idea was to create this simple repository and then add on top of it over time other libraries that would give me the functionality I need (i.e. Auditing, Item Tracking, etc.,). I believed a simple core was the right place to start.
AutoClutch alternatives and similar packages
Based on the "ORM" category.
Alternatively, view AutoClutch alternatives based on common mentions on social networks and blogs.
-
TypeORM
ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms. -
Dapper
Dapper - a simple object mapper for .Net [Moved to: https://github.com/DapperLib/Dapper] -
Entity Framework
EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations. -
SqlSugar
.Net ORM Fastest ORM Simple Easy Sqlite orm Oracle ORM Mysql Orm postgresql ORm SqlServer oRm 达梦 ORM 人大金仓 ORM 神通ORM C# ORM , C# ORM .NET ORM NET5 ORM .NET6 ORM ClickHouse orm QuestDb ,TDengine ORM,OceanBase orm,GaussDB orm ,Tidb orm -
FreeSql
🦄 .NET orm, C# orm, VB.NET orm, Mysql orm, Postgresql orm, SqlServer orm, Oracle orm, Sqlite orm, Firebird orm, 达梦 orm, 人大金仓 orm, 神通 orm, 翰高 orm, 南大通用 orm, 虚谷 orm, 国产 orm, Clickhouse orm, QuestDB orm, MsAccess orm. -
EFCore.BulkExtensions
Entity Framework EF Core efcore Bulk Batch Extensions with BulkCopy in .Net for Insert Update Delete Read (CRUD), Truncate and SaveChanges operations on SQL Server, PostgreSQL, MySQL, SQLite -
Dapper Extensions
Dapper Extensions is a small library that complements Dapper by adding basic CRUD operations (Get, Insert, Update, Delete) for your POCOs. For more advanced querying scenarios, Dapper Extensions provides a predicate system. The goal of this library is to keep your POCOs pure by not requiring any attributes or base class inheritance. -
Entity Framework 6
This is the codebase for Entity Framework 6 (previously maintained at https://entityframework.codeplex.com). Entity Framework Core is maintained at https://github.com/dotnet/efcore. -
Massive
A small, happy, dynamic MicroORM for .NET that will love you forever. -
LINQKit
LINQKit is a free set of extensions for LINQ to SQL and Entity Framework power users. -
NPoco
Simple microORM that maps the results of a query onto a POCO object. Project based on Schotime's branch of PetaPoco -
SmartSql
SmartSql = MyBatis in C# + .NET Core+ Cache(Memory | Redis) + R/W Splitting + PropertyChangedTrack +Dynamic Repository + InvokeSync + Diagnostics -
SQLProvider
A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides. -
LINQ to Twitter
LINQ Provider for the Twitter API (C# Twitter Library) -
Dapper.FastCRUD
fast & light .NET ORM for strongly typed people -
MongoDB Repository pattern implementation
Repository abstraction layer on top of Official MongoDB C# driver -
MongoDB.Entities
A data access library for MongoDB with an elegant api, LINQ support and built-in entity relationship management -
JsonFlatFileDataStore
Simple JSON flat file data store with support for typed and dynamic data. -
MongoFramework
An "Entity Framework"-like interface for MongoDB -
DbExtensions
Data-access framework with a strong focus on query composition, granularity and code aesthetics. -
NReco.Data
Fast DB-independent DAL for .NET Core: abstract queries, SQL commands builder, schema-less data access, POCO mapping (micro-ORM). -
Linq.Expression.Optimizer
System.Linq.Expression expressions optimizer. http://thorium.github.io/Linq.Expression.Optimizer -
KonfDB
Configuration as a Service for multi-tenant, cross-platform applications -
MapDataReader
Super fast mapping DataReader to strongly typed object, Using AOT source generator. -
ObjectStore
.Net Or-Mapper working with dynamically implemented abstract Classes -
MongoRiver.NET
A library for writing .NET MongoDB oplog tailers. -
EntityFramework.DatabaseMigrator
EntityFramework.DatabaseMigrator is a WinForms utility to help manage Entity Framework 6.0+ migrations. -
Excel2SqlServer
Library for importing Excel spreadsheets into SQL Server tables
Tired of breaking your main and manually rebasing outdated pull requests?
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of AutoClutch or a related project?
README
AutoClutch
The simple generic repository
AutoClutch is a tool for getting data. A few years ago I created a much larger much more complicated generic repository for use in the enterprise. While it worked well in .NET 3.5 and Entity Framework 4 adding on more features and extending it to work with the newest versions of .NET and Entity Framework became a laborious task. I decided to create a simple repository with the knowledge I had. The idea was to target the repository for the most current versions of .NET and Entity Framework. With no restrictions on backwards compatibility the idea was to create this simple repository and then add on top of it over time other libraries that would give me the functionality I need (i.e. Auditing, Item Tracking, etc.,). I believed a simple core was the right place to start.
Nuget Package
AutoService includes both the generic repository and a generic service for you to inherit your services from if you wish. https://www.nuget.org/packages/AutoClutch.AutoService/
Install-Package AutoClutch.AutoService
Or if you want just the repository bit
Install-Package AutoClutch.AutoRepo
Data structure
Following the N-Tier course, Part 1 and Part 2, in PluralSight, Onion Architecture Domain Driven Design was referenced for the layout of this generic repository.
Features Included in the Latest Update
Audit Logs
Includes audit support from the Tracker-Enabled-DbContext project (https://github.com/bilal-fazlani/tracker-enabled-dbcontext) (http://bilal-fazlani.github.io/tracker-enabled-dbcontext/).
String Querying
Includes support for querying the data by fluent or with strings. String support provided by the Dynamic Linq project (http://jasonwatmore.com/post/2014/07/16/Dynamic-LINQ-Using-strings-to-sort-by-properties-and-child-object-properties.aspx) (https://github.com/kahanu/System.Linq.Dynamic).
Dependency Injection Example
Here is a simple example of how to use structuremap with AutoRepo. Please note the 'TrackerEnabledDbContext.TrackerContext' class inherits from the 'DbContext' class. So you will have to specify this 'TrackerEnabledDbContext.TrackerContext' for your dependency injection engine to find a concrete class for.
public class DefaultRegistry : Registry {
public DefaultRegistry() {
Scan(
scan => {
scan.TheCallingAssembly();
scan.WithDefaultConventions();
});
For<TrackerEnabledDbContext.TrackerContext>().HybridHttpOrThreadLocalScoped().Use<MyDbContext>();
// The below line is only needed if you are going to use the generic service
// abstraction layer 'AutoClutch.AutoService'.
For(typeof(IService<>)).Use(typeof(Service<>));
For(typeof(IRepository<>)).Use(typeof(Repository<>));
For<IItemService>().Use<ItemService>();
For<IUserService>().Use<UserService>();
Policies.SetAllProperties(prop => prop.OfType<IService<item>>());
Policies.SetAllProperties(prop => prop.OfType<IItemService>());
Policies.SetAllProperties(prop => prop.OfType<IUserService>());
}
Your Code-First Context Class
Please note that your context class has to inherit from 'TrackerEnabledDbContext.TrackerContext'.
namespace LiteratureAssistant.Data
{
using System;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using LiteratureAssistant.Core.Models;
public partial class MyDbContext : TrackerEnabledDbContext.TrackerContext
{
public MyDbContext()
: base("name=MyDbContext")
{
}
public virtual DbSet<changeOrder> changeOrders { get; set; }
public virtual DbSet<changeOrderType> changeOrderTypes { get; set; }
public virtual DbSet<contract> contracts { get; set; }
public virtual DbSet<contractCategory> contractCategories { get; set; }
public virtual DbSet<contractor> contractors { get; set; }
:
:
:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<changeOrder>()
.Property(e => e.engineerEstimate)
.HasPrecision(19, 4);
modelBuilder.Entity<changeOrder>()
.Property(e => e.proposalAmount)
.HasPrecision(19, 4);
modelBuilder.Entity<changeOrder>()
.Property(e => e.bwtApprovalAmount)
.HasPrecision(19, 4);
modelBuilder.Entity<changeOrder>()
.Property(e => e.registeredAmount)
.HasPrecision(19, 4);
:
:
:
}
}
}
Core Service Constructor
To initialize the repository in your Service class use the following example.
namespace LiteratureAssistant.Core.Services
{
public class ItemService : Service<item>, IItemService
{
private readonly IRepository<item> _itemRepository;
private readonly IService<itemAttribute> _itemAttributeService;
private readonly IService<templateAttribute> _templateAttributeService;
public int ItemTemplateId { get; set; }
public ItemService(IRepository<item> itemRepository, IService<itemAttribute> itemAttributeService,
IService<templateAttribute> templateAttributeService) :
base(itemRepository)
{
_itemRepository = itemRepository;
_itemAttributeService = itemAttributeService;
_templateAttributeService = templateAttributeService;
}
:
:
:
Calling the repostory in a method in your core service.
_itemRepository.Update(item);
Or, if your service has inherited IService...
_itemService.Update(item);
Entire Object Graph Updating
In previous versions developers using AutoClutch.would have to break apart their disconnected object graph and update each child separately. This has been done away with in versions 2.0 and later. Now you as the developer no longer has to worry about updating each child element. In the example above, _itemRepository.Update(item); _itemService.Update(item); If the disconnected object "item" has a child element in it "itemChild" and "itemChild" has changed then the above command will update "itemChild" in the database. In previous versions of this library you would have to call "_itemService.update(itemChild)" as a separate call, so this subsequent call is now no longer needed.
Important
Please note that in order to take advantage of the entire object graph update feature you must follow the table, primary key naming convention like this: "[Table Name]Id". So if your table name is "Employee" then your primary key name should be "EmployeeId".
One of planned changes, is to include the naming convention for a primary key "Id", "[Table Name]id", or any other Regex match in an array of matches. If you want to make use of these features right away create a issue and I will try to prioritize this for you. Or better yet, create a pull request!
Using the Queryable method.
var cars = _carRepository.Queryable().Where(i => i.carId == carId).ToList();
Or, if your service has inherited IService...
var cars = _carService.Queryable().Where(i => i.carId == carId).ToList();