All Projects → linq2db → Linq2db.entityframeworkcore

linq2db / Linq2db.entityframeworkcore

Licence: mit
Bring power of Linq To DB to Entity Framework Core projects

Projects that are alternatives of or similar to Linq2db.entityframeworkcore

Pomelo.entityframeworkcore.mysql
Entity Framework Core provider for MySQL and MariaDB built on top of MySqlConnector
Stars: ✭ 2,099 (+1164.46%)
Mutual labels:  orm, entity-framework, entity-framework-core, dotnet-core
Impatient
Ain't nobody got time for data
Stars: ✭ 110 (-33.73%)
Mutual labels:  sql, orm, entity-framework-core, linq
Smartsql
SmartSql = MyBatis in C# + .NET Core+ Cache(Memory | Redis) + R/W Splitting + PropertyChangedTrack +Dynamic Repository + InvokeSync + Diagnostics
Stars: ✭ 775 (+366.87%)
Mutual labels:  sql, orm, dotnet-core
Efcore.pg
Entity Framework Core provider for PostgreSQL
Stars: ✭ 838 (+404.82%)
Mutual labels:  sql, entity-framework, entity-framework-core
System.linq.dynamic.core
The .NET Standard / .NET Core version from the System Linq Dynamic functionality.
Stars: ✭ 864 (+420.48%)
Mutual labels:  sql, entity-framework, linq
Gridify
Easy and optimized way to apply Filtering, Sorting, and Pagination using text-based data.
Stars: ✭ 372 (+124.1%)
Mutual labels:  linq, entity-framework, entity-framework-core
Nopcommerce
The most popular open-source eCommerce shopping cart solution based on ASP.NET Core
Stars: ✭ 6,827 (+4012.65%)
Mutual labels:  sql, entity-framework, dotnet-core
Entityframework.lazyloading
LazyLoading for EF Core
Stars: ✭ 23 (-86.14%)
Mutual labels:  orm, entity-framework, entity-framework-core
Entityframework.docs
Documentation for Entity Framework Core and Entity Framework 6
Stars: ✭ 888 (+434.94%)
Mutual labels:  orm, entity-framework, entity-framework-core
Maikebing.entityframeworkcore.taos
Entity, Framework, EF, Core, Data, O/RM, entity-framework-core,TDengine
Stars: ✭ 113 (-31.93%)
Mutual labels:  orm, entity-framework, entity-framework-core
Nhibernate Core
NHibernate Object Relational Mapper
Stars: ✭ 1,918 (+1055.42%)
Mutual labels:  orm, linq, dotnet-core
Dotnetlabs
.NET Labs -- Show Me the Tips and Tricks and Code
Stars: ✭ 135 (-18.67%)
Mutual labels:  entity-framework, entity-framework-core, dotnet-core
LinqBuilder
LinqBuilder is an advanced implementation of the specification pattern specifically targeting LINQ query generation.
Stars: ✭ 34 (-79.52%)
Mutual labels:  linq, entity-framework, entity-framework-core
Entityframeworkcore.cacheable
EntityFrameworkCore second level cache
Stars: ✭ 138 (-16.87%)
Mutual labels:  orm, entity-framework, dotnet-core
Csharp Datatables Parser
C# Serverside parser for the popuplar jQuery datatables plugin.
Stars: ✭ 119 (-28.31%)
Mutual labels:  entity-framework-core, linq, dotnet-core
Efcore
EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
Stars: ✭ 10,838 (+6428.92%)
Mutual labels:  orm, entity-framework, dotnet-core
Linq2db
Linq to database provider.
Stars: ✭ 2,211 (+1231.93%)
Mutual labels:  sql, orm, linq
Firenze
Adapter based JavaScript ORM for Node.js and the browser
Stars: ✭ 131 (-21.08%)
Mutual labels:  sql, orm
Entityframework Plus
Entity Framework Plus extends your DbContext with must-haves features: Include Filter, Auditing, Caching, Query Future, Batch Delete, Batch Update, and more
Stars: ✭ 1,848 (+1013.25%)
Mutual labels:  entity-framework, entity-framework-core
Etl.net
Mass processing data with a complete ETL for .net developers
Stars: ✭ 129 (-22.29%)
Mutual labels:  entity-framework, dotnet-core

linq2db.EntityFrameworkCore

linq2db.EntityFrameworkCore is an integration of LINQ To DB with existing EntityFrameworkCore projects. It was inspired by this issue in EF.Core repository.

Build status

Azure DevOps builds Azure DevOps builds Azure DevOps builds

Feeds

  • NuGet NuGet
  • Azure Artifacts MyGet (feed)

Unique features

  • Fast Eager Loading (incomparable faster on massive Include query)
  • Global Query Filters optimization
  • Better SQL optimization
  • Use CTE in LINQ queries
  • MERGE statement support
  • Table hints
  • Full Window functions support
  • Fast BulkCopy of millions records
  • Native SQL operations for updating, deleting, inserting records via LINQ query
  • Temporary Tables support
  • Cross Database/Linked Server queries.
  • Full Text Search extensions
  • A lot of extensions to cover ANSI SQL

How to use

In your code you need to initialize integration using following call:

LinqToDBForEFTools.Initialize();

After that you can just call DbContext and IQueryable extension methods, provided by LINQ To DB.

There are many extensions for CRUD Operations missing in vanilla EF (watch our video):

// fast insert big recordsets
ctx.BulkCopy(new BulkCopyOptions {...}, items);

// query for retrieving products that do not have duplicates by Name
var query =
	from p in ctx.Products
	from op in ctx.Products.LeftJoin(op => op.ProductID != p.ProductID && op.Name == p.Name)
	where Sql.ToNullable(op.ProductID) == null
	select p;

// insert these records into the same or another table
query.Insert(ctx.Products.ToLinqToDBTable(), s => new Product { Name = s.Name ... });

// update these records by changing name based on previous value
query.Update(prev => new Product { Name = "U_" + prev.Name ... });

// delete records that matched by query
query.Delete();

Some extensions require LINQ To DB ITable<T> interface, which could be acquired from DbSet<T> using ToLinqToDBTable() extension method.

For ITable<T> interface LINQ To DB provides several extensions that may be useful for complex databases and custom queries:

table = table.TableName("NewTableName");     // change table name in query
table = table.DatabaseName("OtherDatabase"); // change database name, useful for cross database queries.
table = table.OwnerName("OtherOwner");       // change owner.

// inserting into other existing table Products2
query.Insert(ctx.Products.ToLinqToDBTable().TableName("Products2"), s => new Product { Name = s.Name ... });

It is not required to work directly with LINQ To DB DataConnection class but there are several ways to do that. LINQ To DB will try to reuse your configuration and select appropriate data provider:

// uing DbContext
using (var dc = ctx.CreateLinqToDbConnection())
{
   // linq queries using linq2db extensions
}

// using DbContextOptions
using (var dc = options.CreateLinqToDbConnection())
{
   // linq queries using linq2db extensions
}

You can use all LINQ To DB extension functions in your EF linq queries. Just ensure you have called ToLinqToDB() function before materializing objects for synchronous methods.

Since EF Core have defined it's own asynchronous methods, we have to duplicate them to resolve naming collisions. Async methods have the same name but with LinqToDB suffix. E.g. ToListAsyncLinqToDB(), SumAsyncLinqToDB(), ect. The same methods are added whe you need EF Core query processing but there is collision with LINQ To DB and they have extensions with EF suffix - ToListAsyncEF(), SumAsyncEF(), ect.

using (var ctx = CreateAdventureWorksContext())
{
	var productsWithModelCount =
		from p in ctx.Products
		select new
		{
			// Window Function
			Count = Sql.Ext.Count().Over().PartitionBy(p.ProductModelID).ToValue(),
			Product = p
		};

	var neededRecords =
		from p in productsWithModelCount
		where p.Count.Between(2, 4) // LINQ To DB extension
		select new
		{
			p.Product.Name,
			p.Product.Color,
			p.Product.Size,
			// retrieving value from column dynamically
			PhotoFileName = Sql.Property<string>(p.Product, "ThumbnailPhotoFileName")
		};

	// ensure we have replaced EF context
	var items1 = neededRecords.ToLinqToDB().ToArray();       
	
	// async version
	var items2 = await neededRecords.ToLinqToDB().ToArrayAsync(); 
	
	// and simple bonus - how to generate SQL
	var sql = neededRecords.ToLinqToDB().ToString();
}

Also check existing tests in test project for some examples.

Why should I want to use it?

There are many reasons. Some of them:

  • you want to use advanced SQL functionality, not supported or poorly supported by EntityFrameworkCore like BulkCopy support, SQL MERGE operations, convinient DML (Insert/Delete/Update) operations and many-many-many other features LINQ To DB provides, but you need change tracking functionality that EntityFramework provides.
  • you want to migrate to LINQ To DB, but need to do it step-by-step.
  • just because LINQ To DB is cool.

Current status

Below is a list of providers, that should work right now:

  • SQL Server
  • MySQL (including Devart and Pomelo providers)
  • PostgreSQL (Both npgsql and Devart providers)
  • SQLite (including Devart provider)
  • Firebird
  • DB2 LUW
  • Oracle
  • SQL Server CE

Know limitations

  • No Lazy loading
  • No way to work with in-memory database

Help! It doesn't work!

If you encounter any issue with this library, first check issues to see if it was already reported and if not, feel free to report new issue.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].