MoonStorm / FastCrud

fast .NET ORM for strongly typed people
MIT License
506 stars 128 forks source link
dotnet mysql orm postgresql sql sqlanywhere sqlserver

You hate verbatim SQL queries with zero type safety for your code but you love their speed? Dapper.FastCrud is a fast orm built around essential features of the C# 6 / VB 14 that have finally raised the simplicity of raw SQL constructs to acceptable maintenance levels. These features leave no chance to mistypings or problems arising from db entity refactorings.

What to expect when working with Dapper.FastCrud in the DAL?

Type safety, clean code, less prone to errors, more peace of mind, while still being close to the metal. Here's a sample:

// Create paramters for the query
var queryParams = new 
{
    FirstName = "John",
    Street = "Creek Street"
};

// Get persons using the above created query parameters
var persons = dbConnection.Find<Person>(statement => statement
   .WithAlias("person")
   .Include<Address>(join =>
        join.InnerJoin()
            .WithAlias("address"))
   .Where($@"
        {nameof(Person.FirstName):of person} = {nameof(queryParams.FirstName):P} 
        AND {nameof(Address.Street):of address} = {nameof(queryParams.Street):P}")
   .OrderBy($"{nameof(Person.LastName):of person} DESC")  
   .Skip(10)
   .Top(20)
   .WithParameters(queryParams);

Features:

Active Versions

Check the release notes for the main library as well as the model generator for information about the recent changes.

WIKI

The wiki is a great place for learning more about this library.

Speed

Let's have a look at some popular ORMs out there and benchmark their speed:

Automatic Benchmark Report (Last Run: Friday, May 31, 2024)
Library Operation Op Count Time (ms) Time/op (μs)
Dapper insert 10000 1,333.28 133.33
Fast Crud insert 10000 1,396.15 139.62
Dapper Extensions insert 10000 1,513.42 151.34
Simple Crud insert 10000 1,490.36 149.04
Entity Framework - single op/call insert 10000 15,056.93 1,505.69
Dapper update 10000 1,290.22 129.02
Fast Crud update 10000 1,314.45 131.45
Dapper Extensions update 10000 1,541.99 154.20
Simple Crud update 10000 1,381.38 138.14
Entity Framework - single op/call update 10000 27,445.40 2,744.54
Dapper delete 10000 1,209.75 120.98
Fast Crud delete 10000 1,234.92 123.49
Dapper Extensions delete 10000 1,327.86 132.79
Simple Crud delete 10000 1,306.30 130.63
Entity Framework - single op/call delete 10000 2,097.67 209.77
Dapper select by id 10000 569.29 56.93
Fast Crud select by id 10000 570.54 56.35
Dapper Extensions select by id 10000 1,941.33 194.13
Simple Crud select by id 10000 600.45 60.04
Entity Framework select by id 10000 902.95 90.30
Dapper select all 10000 532.22 53.22
Fast Crud select all 10000 574.99 57.50
Dapper Extensions select all 10000 3,012.01 301.20
Simple Crud select all 10000 611.34 61.13
Entity Framework select all 10000 1,465.61 146.56

Dapper is included for reference. All the libs involved get their own internal cache cleared before each run, the benchmark database is re-created, data file gets pre-allocated, and the statistics are turned off. The tests are following the same steps and are running in the same environment on the same number and size of records.

You can find more details about how to run the benchmarks yourself in the wiki.

Install the main library and the model generator via NuGet and enjoy!