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

Commit 75ab81c

Browse files
authored
Merge pull request #62 from linq2db/update_3.1.2
Updating to linq2db 3.1.2
2 parents 7150db8 + 7197aed commit 75ab81c

File tree

7 files changed

+167
-25
lines changed

7 files changed

+167
-25
lines changed

Build/linq2db.Default.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>3.5.0</Version>
3+
<Version>3.6.0</Version>
44

55
<Description>Allows to execute Linq to DB (linq2db) queries in Entity Framework Core DbContext.</Description>
66
<Title>Linq to DB (linq2db) extensions for Entity Framework Core</Title>

NuGet/linq2db.EntityFrameworkCore.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<dependencies>
1717
<group targetFramework=".NETStandard2.0">
1818
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="3.1.3" />
19-
<dependency id="linq2db" version="3.0.1" />
19+
<dependency id="linq2db" version="3.1.2" />
2020
</group>
2121
</dependencies>
2222
</metadata>

Source/LinqToDB.EntityFrameworkCore/Internal/EFCoreExpressionAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public EFCoreExpressionAttribute(string expression) : base(expression)
1414
}
1515

1616
public override ISqlExpression GetExpression(IDataContext dataContext, SelectQuery query,
17-
Expression expression, Func<Expression, ColumnDescriptor?, ISqlExpression> converter)
17+
Expression expression, Func<Expression, ColumnDescriptor, ISqlExpression> converter)
1818
{
1919
var knownExpressions = new List<Expression>();
2020
if (expression.NodeType == ExpressionType.Call)

Source/LinqToDB.EntityFrameworkCore/Internal/LinqToDBForEFQueryProvider.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,18 @@ public TResult Execute<TResult>(Expression expression)
5959
private static MethodInfo _executeAsyncMethodInfo =
6060
MemberHelper.MethodOf((IQueryProviderAsync p) => p.ExecuteAsync<int>(null, default)).GetGenericMethodDefinition();
6161

62+
public Task<IAsyncEnumerable<TResult>> ExecuteAsyncEnumerable<TResult>(Expression expression, CancellationToken token)
63+
{
64+
return QueryProvider.ExecuteAsyncEnumerable<TResult>(expression, token);
65+
}
66+
6267
TResult IAsyncQueryProvider.ExecuteAsync<TResult>(Expression expression, CancellationToken cancellationToken)
6368
{
6469
var item = typeof(TResult).GetGenericArguments()[0];
6570
var method = _executeAsyncMethodInfo.MakeGenericMethod(item);
6671
return (TResult) method.Invoke(QueryProvider, new object[] { expression, cancellationToken });
6772
}
6873

69-
public System.Collections.Generic.IAsyncEnumerable<TResult> ExecuteAsync<TResult>(Expression expression)
70-
{
71-
return QueryProvider.ExecuteAsync<TResult>(expression);
72-
}
73-
74-
IAsyncEnumerable<TResult> IQueryProviderAsync.ExecuteAsync<TResult>(Expression expression)
75-
{
76-
return QueryProvider.ExecuteAsync<TResult>(expression);
77-
}
78-
7974
public Task<TResult> ExecuteAsync<TResult>(Expression expression, CancellationToken cancellationToken)
8075
{
8176
return QueryProvider.ExecuteAsync<TResult>(expression, cancellationToken);
@@ -99,10 +94,9 @@ IEnumerator IEnumerable.GetEnumerator()
9994

10095
#endregion
10196

102-
System.Collections.Generic.IAsyncEnumerator<T> System.Collections.Generic.IAsyncEnumerable<T>.GetAsyncEnumerator(CancellationToken cancellationToken)
97+
public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken)
10398
{
104-
return ExecuteAsync<T>(Expression).GetAsyncEnumerator(cancellationToken);
99+
return QueryProvider.ExecuteAsyncEnumerable<T>(Expression, cancellationToken).Result.GetAsyncEnumerator(cancellationToken);
105100
}
106-
107101
}
108102
}

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFTools.ContextExtensions.cs

Lines changed: 154 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
3-
3+
using System.Threading;
4+
using System.Threading.Tasks;
45
using Microsoft.EntityFrameworkCore;
56

67
using JetBrains.Annotations;
@@ -22,7 +23,7 @@ public static partial class LinqToDBForEFTools
2223
/// <param name="options">Operation options.</param>
2324
/// <param name="source">Records to insert.</param>
2425
/// <returns>Bulk insert operation status.</returns>
25-
public static BulkCopyRowsCopied BulkCopy<T>([NotNull] this DbContext context, BulkCopyOptions options, IEnumerable<T> source) where T : class
26+
public static BulkCopyRowsCopied BulkCopy<T>([JetBrains.Annotations.NotNull] this DbContext context, BulkCopyOptions options, IEnumerable<T> source) where T : class
2627
{
2728
if (context == null) throw new ArgumentNullException(nameof(context));
2829

@@ -40,7 +41,7 @@ public static BulkCopyRowsCopied BulkCopy<T>([NotNull] this DbContext context, B
4041
/// <param name="maxBatchSize">Number of rows in each batch. At the end of each batch, the rows in the batch are sent to the server. </param>
4142
/// <param name="source">Records to insert.</param>
4243
/// <returns>Bulk insert operation status.</returns>
43-
public static BulkCopyRowsCopied BulkCopy<T>([NotNull] this DbContext context, int maxBatchSize, IEnumerable<T> source) where T : class
44+
public static BulkCopyRowsCopied BulkCopy<T>([JetBrains.Annotations.NotNull] this DbContext context, int maxBatchSize, IEnumerable<T> source) where T : class
4445
{
4546
if (context == null) throw new ArgumentNullException(nameof(context));
4647

@@ -59,7 +60,7 @@ public static BulkCopyRowsCopied BulkCopy<T>([NotNull] this DbContext context, i
5960
/// <param name="context">Database context.</param>
6061
/// <param name="source">Records to insert.</param>
6162
/// <returns>Bulk insert operation status.</returns>
62-
public static BulkCopyRowsCopied BulkCopy<T>([NotNull] this DbContext context, IEnumerable<T> source) where T : class
63+
public static BulkCopyRowsCopied BulkCopy<T>([JetBrains.Annotations.NotNull] this DbContext context, IEnumerable<T> source) where T : class
6364
{
6465
if (context == null) throw new ArgumentNullException(nameof(context));
6566

@@ -73,6 +74,153 @@ public static BulkCopyRowsCopied BulkCopy<T>([NotNull] this DbContext context, I
7374

7475
#endregion
7576

77+
#region BulkCopyAsync
78+
79+
/// <summary>Asynchronously performs bulk insert operation.</summary>
80+
/// <typeparam name="T">Mapping type of inserted record.</typeparam>
81+
/// <param name="context">Database context.</param>
82+
/// <param name="options">Operation options.</param>
83+
/// <param name="source">Records to insert.</param>
84+
/// <param name="cancellationToken">Asynchronous operation cancellation token.</param>
85+
/// <returns>Task with bulk insert operation status.</returns>
86+
public static Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
87+
[JetBrains.Annotations.NotNull] this DbContext context,
88+
BulkCopyOptions options,
89+
IEnumerable<T> source,
90+
CancellationToken cancellationToken = default)
91+
where T : class
92+
{
93+
if (context == null) throw new ArgumentNullException(nameof(context));
94+
if (source == null) throw new ArgumentNullException(nameof(source));
95+
96+
using (var dc = context.CreateLinqToDbConnection())
97+
{
98+
return dc.BulkCopyAsync(options, source, cancellationToken);
99+
}
100+
}
101+
102+
/// <summary>Asynchronously performs bulk insert operation.</summary>
103+
/// <typeparam name="T">Mapping type of inserted record.</typeparam>
104+
/// <param name="context">Database context.</param>
105+
/// <param name="maxBatchSize">
106+
/// Number of rows in each batch. At the end of each batch, the rows in the batch are sent to
107+
/// the server.
108+
/// </param>
109+
/// <param name="source">Records to insert.</param>
110+
/// <param name="cancellationToken">Asynchronous operation cancellation token.</param>
111+
/// <returns>Task with bulk insert operation status.</returns>
112+
public static Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
113+
[JetBrains.Annotations.NotNull] this DbContext context,
114+
int maxBatchSize,
115+
IEnumerable<T> source,
116+
CancellationToken cancellationToken = default)
117+
where T : class
118+
{
119+
if (context == null) throw new ArgumentNullException(nameof(context));
120+
if (source == null) throw new ArgumentNullException(nameof(source));
121+
122+
if (context == null) throw new ArgumentNullException(nameof(context));
123+
if (source == null) throw new ArgumentNullException(nameof(source));
124+
125+
using (var dc = context.CreateLinqToDbConnection())
126+
{
127+
return dc.BulkCopyAsync(maxBatchSize, source, cancellationToken);
128+
}
129+
}
130+
131+
/// <summary>Asynchronously performs bulk insert operation.</summary>
132+
/// <typeparam name="T">Mapping type of inserted record.</typeparam>
133+
/// <param name="context">Database context.</param>
134+
/// <param name="source">Records to insert.</param>
135+
/// <param name="cancellationToken">Asynchronous operation cancellation token.</param>
136+
/// <returns>Task with bulk insert operation status.</returns>
137+
public static Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
138+
[JetBrains.Annotations.NotNull] this DbContext context,
139+
IEnumerable<T> source,
140+
CancellationToken cancellationToken = default)
141+
where T : class
142+
{
143+
if (context == null) throw new ArgumentNullException(nameof(context));
144+
if (source == null) throw new ArgumentNullException(nameof(source));
145+
146+
using (var dc = context.CreateLinqToDbConnection())
147+
{
148+
return dc.BulkCopyAsync(source, cancellationToken);
149+
}
150+
}
151+
152+
/// <summary>Asynchronously performs bulk insert operation.</summary>
153+
/// <typeparam name="T">Mapping type of inserted record.</typeparam>
154+
/// <param name="context">Database context.</param>
155+
/// <param name="options">Operation options.</param>
156+
/// <param name="source">Records to insert.</param>
157+
/// <param name="cancellationToken">Asynchronous operation cancellation token.</param>
158+
/// <returns>Task with bulk insert operation status.</returns>
159+
public static Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
160+
[JetBrains.Annotations.NotNull] this DbContext context,
161+
BulkCopyOptions options,
162+
IAsyncEnumerable<T> source,
163+
CancellationToken cancellationToken = default)
164+
where T : class
165+
{
166+
if (context == null) throw new ArgumentNullException(nameof(context));
167+
if (source == null) throw new ArgumentNullException(nameof(source));
168+
169+
using (var dc = context.CreateLinqToDbConnection())
170+
{
171+
return dc.BulkCopyAsync(options, source, cancellationToken);
172+
}
173+
}
174+
175+
/// <summary>Asynchronously performs bulk insert operation.</summary>
176+
/// <typeparam name="T">Mapping type of inserted record.</typeparam>
177+
/// <param name="context">Database context.</param>
178+
/// <param name="maxBatchSize">
179+
/// Number of rows in each batch. At the end of each batch, the rows in the batch are sent to
180+
/// the server.
181+
/// </param>
182+
/// <param name="source">Records to insert.</param>
183+
/// <param name="cancellationToken">Asynchronous operation cancellation token.</param>
184+
/// <returns>Task with bulk insert operation status.</returns>
185+
public static Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
186+
[JetBrains.Annotations.NotNull] this DbContext context,
187+
int maxBatchSize,
188+
IAsyncEnumerable<T> source,
189+
CancellationToken cancellationToken = default)
190+
where T : class
191+
{
192+
if (context == null) throw new ArgumentNullException(nameof(context));
193+
if (source == null) throw new ArgumentNullException(nameof(source));
194+
195+
using (var dc = context.CreateLinqToDbConnection())
196+
{
197+
return dc.BulkCopyAsync(maxBatchSize, source, cancellationToken);
198+
}
199+
}
200+
201+
/// <summary>Asynchronously performs bulk insert operation.</summary>
202+
/// <typeparam name="T">Mapping type of inserted record.</typeparam>
203+
/// <param name="context">Database context.</param>
204+
/// <param name="source">Records to insert.</param>
205+
/// <param name="cancellationToken">Asynchronous operation cancellation token.</param>
206+
/// <returns>Task with bulk insert operation status.</returns>
207+
public static Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
208+
[JetBrains.Annotations.NotNull] this DbContext context,
209+
IAsyncEnumerable<T> source,
210+
CancellationToken cancellationToken = default)
211+
where T : class
212+
{
213+
if (context == null) throw new ArgumentNullException(nameof(context));
214+
if (source == null) throw new ArgumentNullException(nameof(source));
215+
216+
using (var dc = context.CreateLinqToDbConnection())
217+
{
218+
return dc.BulkCopyAsync(source, cancellationToken);
219+
}
220+
}
221+
222+
#endregion
223+
76224
#region Value Insertable
77225

78226
/// <summary>
@@ -84,7 +232,7 @@ public static BulkCopyRowsCopied BulkCopy<T>([NotNull] this DbContext context, I
84232
/// <returns>Insertable source query.</returns>
85233
[LinqTunnel]
86234
[Pure]
87-
public static IValueInsertable<T> Into<T>([NotNull] this DbContext context, [NotNull] ITable<T> target)
235+
public static IValueInsertable<T> Into<T>([JetBrains.Annotations.NotNull] this DbContext context, [JetBrains.Annotations.NotNull] ITable<T> target)
88236
{
89237
if (context == null) throw new ArgumentNullException(nameof(context));
90238
if (target == null) throw new ArgumentNullException(nameof(target));
@@ -101,7 +249,7 @@ public static IValueInsertable<T> Into<T>([NotNull] this DbContext context, [Not
101249
/// </summary>
102250
/// <typeparam name="T">Mapping class type.</typeparam>
103251
/// <returns>Queryable source.</returns>
104-
public static ITable<T> GetTable<T>([NotNull] this DbContext context)
252+
public static ITable<T> GetTable<T>([JetBrains.Annotations.NotNull] this DbContext context)
105253
where T : class
106254
{
107255
if (context == null) throw new ArgumentNullException(nameof(context));

Source/LinqToDB.EntityFrameworkCore/linq2db.EntityFrameworkCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="linq2db" Version="3.0.0" />
12+
<PackageReference Include="linq2db" Version="3.1.2" />
1313
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.3" />
1414
</ItemGroup>
1515

azure-pipelines.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
variables:
22
solution: 'linq2db.EFCore.sln'
33
build_configuration: 'Release'
4-
assemblyVersion: 3.5.0
5-
nugetVersion: 3.5.0
4+
assemblyVersion: 3.6.0
5+
nugetVersion: 3.6.0
66
artifact_nugets: 'nugets'
77

88
# build on commits to important branches (master + release branches):

0 commit comments

Comments
 (0)