{"id":13780253,"url":"https://github.com/linq2db/linq2db.EntityFrameworkCore","last_synced_at":"2025-05-11T13:31:42.326Z","repository":{"id":34431526,"uuid":"131035682","full_name":"linq2db/linq2db.EntityFrameworkCore","owner":"linq2db","description":"Bring power of Linq To DB to Entity Framework Core projects","archived":false,"fork":false,"pushed_at":"2024-11-13T12:49:48.000Z","size":2835,"stargazers_count":470,"open_issues_count":1,"forks_count":38,"subscribers_count":24,"default_branch":"master","last_synced_at":"2024-11-13T13:44:13.407Z","etag":null,"topics":["dotnet-core","entity-framework","entity-framework-core","entityframeworkcore","linq","linq2db","orm","sql"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linq2db.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-25T16:37:20.000Z","updated_at":"2024-11-13T12:39:10.000Z","dependencies_parsed_at":"2024-03-04T14:49:59.209Z","dependency_job_id":"ac2f13c7-666e-44e7-8250-01a830a830c7","html_url":"https://github.com/linq2db/linq2db.EntityFrameworkCore","commit_stats":{"total_commits":228,"total_committers":10,"mean_commits":22.8,"dds":"0.17982456140350878","last_synced_commit":"464711fc80c12fbbfa56584ca549e96018e6f7bb"},"previous_names":[],"tags_count":118,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linq2db%2Flinq2db.EntityFrameworkCore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linq2db%2Flinq2db.EntityFrameworkCore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linq2db%2Flinq2db.EntityFrameworkCore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linq2db%2Flinq2db.EntityFrameworkCore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linq2db","download_url":"https://codeload.github.com/linq2db/linq2db.EntityFrameworkCore/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225056780,"owners_count":17414207,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dotnet-core","entity-framework","entity-framework-core","entityframeworkcore","linq","linq2db","orm","sql"],"created_at":"2024-08-03T18:01:13.813Z","updated_at":"2025-05-11T13:31:42.300Z","avatar_url":"https://github.com/linq2db.png","language":"C#","readme":"# Repository was merged with [main repository](https://github.com/linq2db/linq2db)\n\n# linq2db.EntityFrameworkCore\n\n`linq2db.EntityFrameworkCore` is an integration of `LINQ To DB` with existing EntityFrameworkCore projects. It was inspired by [this issue](https://github.com/aspnet/EntityFrameworkCore/issues/11657) in EF.Core repository.\n\n## Build status\n\n[![Azure DevOps builds](https://img.shields.io/azure-devops/build/linq2db/0dcc414b-ea54-451e-a54f-d63f05367c4b/7/master?label=master)](https://dev.azure.com/linq2db/linq2db/_build?definitionId=7)\n[![Azure DevOps builds](https://img.shields.io/azure-devops/build/linq2db/0dcc414b-ea54-451e-a54f-d63f05367c4b/7?label=latest)](https://dev.azure.com/linq2db/linq2db/_build?definitionId=7)\n[![Azure DevOps builds](https://img.shields.io/azure-devops/build/linq2db/0dcc414b-ea54-451e-a54f-d63f05367c4b/7/version1?label=efcore%202%20master)](https://dev.azure.com/linq2db/linq2db/_build?definitionId=7)\n\n## Feeds\n\n* NuGet [![NuGet](https://img.shields.io/nuget/vpre/linq2db.EntityFrameworkCore.svg)](https://www.nuget.org/packages/linq2db.EntityFrameworkCore)\n* Azure Artifacts [![MyGet](https://img.shields.io/badge/azure-download-yellowgreen)](https://dev.azure.com/linq2db/linq2db/_packaging?_a=package\u0026feed=linq2db\u0026view=versions\u0026package=linq2db.EntityFrameworkCore\u0026protocolType=NuGet) ([feed]( https://pkgs.dev.azure.com/linq2db/linq2db/_packaging/linq2db/nuget/v3/index.json))\n\n# Unique features\n* Fast Eager Loading (incomparable faster on massive `Include` query)\n* Global Query Filters optimization\n* Better SQL optimization\n* [Use CTE in LINQ queries](https://linq2db.github.io/articles/sql/CTE.html)\n* [MERGE statement support](https://linq2db.github.io/articles/sql/merge/Merge-API-Description.html)\n* Table hints\n* [Full Window functions support](https://linq2db.github.io/articles/sql/Window-Functions-(Analytic-Functions).html)\n* Fast [BulkCopy](https://linq2db.github.io/articles/sql/Bulk-Copy.html) of millions records\n* Native SQL operations for updating, deleting, inserting records via LINQ query\n* Temporary Tables support\n* Cross Database/Linked Server queries.\n* Full Text Search extensions\n* A lot of extensions to cover ANSI SQL\n# How to use\n\nIn your code you need to initialize integration using following call:\n\n```cs\nLinqToDBForEFTools.Initialize();\n```\n\nAfter that you can just call DbContext and IQueryable extension methods, provided by `LINQ To DB`.\n\nYou can also register additional options (like interceptors) for LinqToDB during EF context registration, here is an example:\n\n```cs\nvar optionsBuilder = new DbContextOptionsBuilder\u003cMyDbContext\u003e();\noptionsBuilder.UseSqlite();\noptionsBuilder.UseLinqToDB(builder =\u003e\n{\n    // add custom command interceptor\n    builder.AddInterceptor(new MyCommandInterceptor());\n    // add additional mappings\n    builder.AddMappingSchema(myCustomMappings);\n    // configure SQL Server dialect explicitly\n    builder.AddCustomOptions(o =\u003e o.UseSqlServer(SqlServerVersion.v2022));\n});\n```\n\nThere are many extensions for CRUD Operations missing in vanilla EF ([watch our video](https://www.youtube.com/watch?v=m--oX73EGeQ)):\n\n```cs\n// fast insert big recordsets\nctx.BulkCopy(new BulkCopyOptions {...}, items);\n\n// query for retrieving products that do not have duplicates by Name\nvar query =\n    from p in ctx.Products\n    from op in ctx.Products.LeftJoin(op =\u003e op.ProductID != p.ProductID \u0026\u0026 op.Name == p.Name)\n    where Sql.ToNullable(op.ProductID) == null\n    select p;\n\n// insert these records into the same or another table\nquery.Insert(ctx.Products.ToLinqToDBTable(), s =\u003e new Product { Name = s.Name ... });\n\n// update these records by changing name based on previous value\nquery.Update(prev =\u003e new Product { Name = \"U_\" + prev.Name ... });\n\n// delete records that matched by query\nquery.Delete();\n```\n\nSome extensions require LINQ To DB `ITable\u003cT\u003e` interface, which could be acquired from  `DbSet\u003cT\u003e` using `ToLinqToDBTable()` extension method. \n\nFor `ITable\u003cT\u003e` interface LINQ To DB provides several extensions that may be useful for complex databases and custom queries:\n\n```cs\ntable = table.TableName(\"NewTableName\");     // change table name in query\ntable = table.DatabaseName(\"OtherDatabase\"); // change database name, useful for cross database queries.\ntable = table.OwnerName(\"OtherOwner\");       // change owner.\n\n// inserting into other existing table Products2\nquery.Insert(ctx.Products.ToLinqToDBTable().TableName(\"Products2\"), s =\u003e new Product { Name = s.Name ... });\n```\n\nIt 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:\n\n```cs\n// uing DbContext\nusing (var dc = ctx.CreateLinqToDBConnection())\n{\n   // linq queries using linq2db extensions\n}\n\n// using DbContextOptions\nusing (var dc = options.CreateLinqToDBConnection())\n{\n   // linq queries using linq2db extensions\n}\n```\n\nYou 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.\n\nSince EF Core have defined it's own asynchronous methods, we have to duplicate them to resolve naming collisions. \nAsync 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.\n\n```cs\nusing (var ctx = CreateAdventureWorksContext())\n{\n    var productsWithModelCount =\n        from p in ctx.Products\n        select new\n        {\n            // Window Function\n            Count = Sql.Ext.Count().Over().PartitionBy(p.ProductModelID).ToValue(),\n            Product = p\n        };\n\n    var neededRecords =\n        from p in productsWithModelCount\n        where p.Count.Between(2, 4) // LINQ To DB extension\n        select new\n        {\n            p.Product.Name,\n            p.Product.Color,\n            p.Product.Size,\n            // retrieving value from column dynamically\n            PhotoFileName = Sql.Property\u003cstring\u003e(p.Product, \"ThumbnailPhotoFileName\")\n        };\n\n    // ensure we have replaced EF context\n    var items1 = neededRecords.ToLinqToDB().ToArray();       \n    \n    // async version\n    var items2 = await neededRecords.ToLinqToDB().ToArrayAsync(); \n    \n    // and simple bonus - how to generate SQL\n    var sql = neededRecords.ToLinqToDB().ToString();\n}\n```\n\nAlso check [existing tests](https://github.com/linq2db/linq2db.EntityFrameworkCore/blob/master/Tests/LinqToDB.EntityFrameworkCore.Tests/ToolsTests.cs) in test project for some examples.\n\n# Why should I want to use it?\n\nThere are many reasons. Some of them:\n\n- 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.\n- you want to migrate to LINQ To DB, but need to do it step-by-step.\n- just because LINQ To DB is cool.\n\n# Current status\n\nBelow is a list of providers, that should work right now:\n\n- SQL Server\n- MySQL (including Devart and Pomelo providers)\n- PostgreSQL (Both npgsql and Devart providers)\n- SQLite (including Devart provider)\n- Firebird\n- DB2 LUW\n- Oracle\n- SQL Server CE\n\n# Known limitations\n- No Lazy loading\n- No way to work with in-memory database\n- No TPT (table per type) support\n- No many-to-many support\n\n# Help! It doesn't work!\n\nIf 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.\n","funding_links":[],"categories":["EF Core","C\\#"],"sub_categories":["📦 Libraries"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinq2db%2Flinq2db.EntityFrameworkCore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinq2db%2Flinq2db.EntityFrameworkCore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinq2db%2Flinq2db.EntityFrameworkCore/lists"}