Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Commit 34777c7

Browse files
authored
backport linq2db 5 migration from v7 (#297)
1 parent 1e56b40 commit 34777c7

34 files changed

+869
-907
lines changed

Build/linq2db.Default.props

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>6.11.0</Version>
3+
<Version>6.12.0</Version>
44

55
<Authors>Svyatoslav Danyliv, Igor Tkachev, Dmitry Lukashenko, Ilya Chudin</Authors>
66
<Product>Linq to DB</Product>
77
<Company>linq2db.net</Company>
8-
<Copyright>2002-2022 linq2db.net</Copyright>
8+
<Copyright>2002-2023 linq2db.net</Copyright>
99
<RepositoryUrl>https://github.com/linq2db/linq2db.EntityFrameworkCore</RepositoryUrl>
1010
<RepositoryType>git</RepositoryType>
1111

Directory.Packages.props

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<Project>
22
<ItemGroup>
3-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
3+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
44
<PackageVersion Include="NUnit3TestAdapter" Version="4.3.1" />
55
<PackageVersion Include="NUnit" Version="3.13.3" />
6-
<PackageVersion Include="FluentAssertions" Version="6.8.0" />
6+
<PackageVersion Include="FluentAssertions" Version="6.10.0" />
77

8-
<PackageVersion Include="linq2db" Version="4.4.0" />
9-
<PackageVersion Include="linq2db.Tools" Version="4.4.0" />
8+
<PackageVersion Include="linq2db" Version="5.0.0" />
9+
<PackageVersion Include="linq2db.Tools" Version="5.0.0" />
1010

1111
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
1212

@@ -17,11 +17,11 @@
1717
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
1818

1919
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.2" />
20-
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.7" />
21-
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.12" />
22-
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.12" />
20+
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.8" />
21+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.14" />
22+
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.14" />
2323

2424
<PackageVersion Include="EntityFrameworkCore.FSharp" Version="6.0.7" />
25-
<PackageVersion Include="FSharp.Core" Version="7.0.0" />
25+
<PackageVersion Include="FSharp.Core" Version="7.0.200" />
2626
</ItemGroup>
2727
</Project>

NuGet/linq2db.EntityFrameworkCore.nuspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<title>Linq to DB (linq2db) extensions for Entity Framework Core</title>
66
<authors>Igor Tkachev, Ilya Chudin, Svyatoslav Danyliv, Dmitry Lukashenko</authors>
77
<owners>Igor Tkachev, Ilya Chudin, Svyatoslav Danyliv, Dmitry Lukashenko</owners>
8-
<copyright>Copyright © 2020-2022 Igor Tkachev, Ilya Chudin, Svyatoslav Danyliv, Dmitry Lukashenko</copyright>
8+
<copyright>Copyright © 2020-2023 Igor Tkachev, Ilya Chudin, Svyatoslav Danyliv, Dmitry Lukashenko</copyright>
99
<description>Allows to execute Linq to DB (linq2db) queries in Entity Framework Core DbContext.</description>
1010
<summary />
1111
<tags>linq linq2db LinqToDB ORM database entity-framework-core EntityFrameworkCore EFCore DB SQL SqlServer SqlCe SqlServerCe MySql Firebird SQLite Oracle ODP PostgreSQL DB2</tags>
@@ -16,7 +16,7 @@
1616
<dependencies>
1717
<group targetFramework="net6.0">
1818
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="6.0.5" />
19-
<dependency id="linq2db" version="4.4.0" />
19+
<dependency id="linq2db" version="5.0.0" />
2020
</group>
2121
</dependencies>
2222
</metadata>

README.md

+47-37
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,17 @@ You can also register additional options (like interceptors) for LinqToDB during
4444
```cs
4545
var optionsBuilder = new DbContextOptionsBuilder<MyDbContext>();
4646
optionsBuilder.UseSqlite();
47-
optionsBuilder.UseLinqToDb(builder =>
47+
optionsBuilder.UseLinqToDB(builder =>
4848
{
49+
// add custom command interceptor
4950
builder.AddInterceptor(new MyCommandInterceptor());
51+
// add additional mappings
52+
builder.AddMappingSchema(myCustomMappings);
53+
// configure SQL Server dialect explicitly
54+
//builder.AddCustomOptions(o => o.UseSqlServer(SqlServerVersion.v2022));
55+
// due to bug in linq2db 5.0.0, use overload with connection string
56+
// will be fixed in next linq2db release
57+
builder.AddCustomOptions(o => o.UseSqlServer("unused", SqlServerVersion.v2022));
5058
});
5159
```
5260

@@ -58,10 +66,10 @@ ctx.BulkCopy(new BulkCopyOptions {...}, items);
5866

5967
// query for retrieving products that do not have duplicates by Name
6068
var query =
61-
from p in ctx.Products
62-
from op in ctx.Products.LeftJoin(op => op.ProductID != p.ProductID && op.Name == p.Name)
63-
where Sql.ToNullable(op.ProductID) == null
64-
select p;
69+
from p in ctx.Products
70+
from op in ctx.Products.LeftJoin(op => op.ProductID != p.ProductID && op.Name == p.Name)
71+
where Sql.ToNullable(op.ProductID) == null
72+
select p;
6573

6674
// insert these records into the same or another table
6775
query.Insert(ctx.Products.ToLinqToDBTable(), s => new Product { Name = s.Name ... });
@@ -90,13 +98,13 @@ It is not required to work directly with `LINQ To DB` `DataConnection` class but
9098

9199
```cs
92100
// uing DbContext
93-
using (var dc = ctx.CreateLinqToDbConnection())
101+
using (var dc = ctx.CreateLinqToDBConnection())
94102
{
95103
// linq queries using linq2db extensions
96104
}
97105

98106
// using DbContextOptions
99-
using (var dc = options.CreateLinqToDbConnection())
107+
using (var dc = options.CreateLinqToDBConnection())
100108
{
101109
// linq queries using linq2db extensions
102110
}
@@ -110,35 +118,35 @@ Async methods have the same name but with `LinqToDB` suffix. E.g. `ToListAsyncLi
110118
```cs
111119
using (var ctx = CreateAdventureWorksContext())
112120
{
113-
var productsWithModelCount =
114-
from p in ctx.Products
115-
select new
116-
{
117-
// Window Function
118-
Count = Sql.Ext.Count().Over().PartitionBy(p.ProductModelID).ToValue(),
119-
Product = p
120-
};
121-
122-
var neededRecords =
123-
from p in productsWithModelCount
124-
where p.Count.Between(2, 4) // LINQ To DB extension
125-
select new
126-
{
127-
p.Product.Name,
128-
p.Product.Color,
129-
p.Product.Size,
130-
// retrieving value from column dynamically
131-
PhotoFileName = Sql.Property<string>(p.Product, "ThumbnailPhotoFileName")
132-
};
133-
134-
// ensure we have replaced EF context
135-
var items1 = neededRecords.ToLinqToDB().ToArray();
136-
137-
// async version
138-
var items2 = await neededRecords.ToLinqToDB().ToArrayAsync();
139-
140-
// and simple bonus - how to generate SQL
141-
var sql = neededRecords.ToLinqToDB().ToString();
121+
var productsWithModelCount =
122+
from p in ctx.Products
123+
select new
124+
{
125+
// Window Function
126+
Count = Sql.Ext.Count().Over().PartitionBy(p.ProductModelID).ToValue(),
127+
Product = p
128+
};
129+
130+
var neededRecords =
131+
from p in productsWithModelCount
132+
where p.Count.Between(2, 4) // LINQ To DB extension
133+
select new
134+
{
135+
p.Product.Name,
136+
p.Product.Color,
137+
p.Product.Size,
138+
// retrieving value from column dynamically
139+
PhotoFileName = Sql.Property<string>(p.Product, "ThumbnailPhotoFileName")
140+
};
141+
142+
// ensure we have replaced EF context
143+
var items1 = neededRecords.ToLinqToDB().ToArray();
144+
145+
// async version
146+
var items2 = await neededRecords.ToLinqToDB().ToArrayAsync();
147+
148+
// and simple bonus - how to generate SQL
149+
var sql = neededRecords.ToLinqToDB().ToString();
142150
}
143151
```
144152

@@ -165,9 +173,11 @@ Below is a list of providers, that should work right now:
165173
- Oracle
166174
- SQL Server CE
167175

168-
# Know limitations
176+
# Known limitations
169177
- No Lazy loading
170178
- No way to work with in-memory database
179+
- No TPT (table per type) support
180+
- No many-to-many support
171181

172182
# Help! It doesn't work!
173183

0 commit comments

Comments
 (0)