Skip to content

Commit 2d93954

Browse files
committed
#29 model out the asynchrounous interfaces. set namespace friendly names so they will not break once the runtime starts supporting.
1 parent 2a89718 commit 2d93954

File tree

9 files changed

+162
-10
lines changed

9 files changed

+162
-10
lines changed

SubSonic/Infrastructure/Builders/DbSqlQueryBuilder/DbSqlQueryBuilderQueryProvider.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ public IQueryable<TEntity> CreateQuery<TEntity>(Expression expression)
3434
return new SubSonicCollection<TEntity>(this, BuildQuery(expression));
3535
}
3636

37+
private TResult Scalar<TResult>(IDataRecord reader)
38+
{
39+
if (reader.FieldCount > 1)
40+
{
41+
throw new InvalidOperationException();
42+
}
43+
44+
return (TResult)Convert.ChangeType(reader[0], typeof(TResult), CultureInfo.CurrentCulture);
45+
}
46+
3747
public TResult Execute<TResult>(Expression expression)
3848
{
3949
if (expression is null)
@@ -161,21 +171,31 @@ public TResult Execute<TResult>(Expression expression)
161171
throw new NotSupportedException(expression.ToString());
162172
}
163173

164-
private TResult Scalar<TResult>(IDataRecord reader)
174+
public async Task<TResult> ExecuteAsync<TResult>(Expression expression)
165175
{
166-
if (reader.FieldCount > 1)
176+
if (expression is null)
167177
{
168-
throw new InvalidOperationException();
178+
throw Error.ArgumentNull(nameof(expression));
169179
}
170180

171-
return (TResult)Convert.ChangeType(reader[0], typeof(TResult), CultureInfo.CurrentCulture);
181+
throw Error.NotImplemented();
182+
}
183+
184+
public async Task<object> ExecuteAsync(Expression expression)
185+
{
186+
if (expression is null)
187+
{
188+
throw Error.ArgumentNull(nameof(expression));
189+
}
190+
191+
throw Error.NotImplemented();
172192
}
173193

174194
public object Execute(Expression expression)
175195
{
176196
if (expression is null)
177197
{
178-
throw new ArgumentNullException(nameof(expression));
198+
throw Error.ArgumentNull(nameof(expression));
179199
}
180200

181201
if (expression is DbExpression query)

SubSonic/Infrastructure/Builders/DbSqlTableTypeProvider.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Linq.Expressions;
66
using System.Reflection;
7+
using System.Threading.Tasks;
78

89
namespace SubSonic.Infrastructure.Builders
910
{
@@ -130,14 +131,44 @@ public IQueryable<TElement> CreateQuery<TElement>(Expression expression)
130131
}
131132
}
132133

134+
public async Task<TResult> ExecuteAsync<TResult>(Expression expression)
135+
{
136+
if (expression is null)
137+
{
138+
throw Error.ArgumentNull(nameof(expression));
139+
}
140+
141+
throw Error.NotImplemented();
142+
}
143+
144+
public async Task<object> ExecuteAsync(Expression expression)
145+
{
146+
if (expression is null)
147+
{
148+
throw Error.ArgumentNull(nameof(expression));
149+
}
150+
151+
throw Error.NotImplemented();
152+
}
153+
133154
public object Execute(Expression expression)
134155
{
135-
throw new NotImplementedException();
156+
if (expression is null)
157+
{
158+
throw Error.ArgumentNull(nameof(expression));
159+
}
160+
161+
throw Error.NotImplemented();
136162
}
137163

138164
public TResult Execute<TResult>(Expression expression)
139165
{
140-
throw new NotImplementedException();
166+
if (expression is null)
167+
{
168+
throw Error.ArgumentNull(nameof(expression));
169+
}
170+
171+
throw Error.NotImplemented();
141172
}
142173

143174
public IDbPagedQuery ToPagedQuery(Expression expression, int size = 20)

SubSonic/Infrastructure/Database/SubSonicQueryable.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace SubSonic.Infrastructure
1010
using Linq.Expressions;
1111
using Logging;
1212
using Schema;
13+
using SubSonic.Interfaces;
1314

1415
public sealed class SubSonicCollection<TElement>
1516
: SubSonicCollection
@@ -33,6 +34,19 @@ public SubSonicCollection(IQueryProvider provider, Expression expression, IEnume
3334

3435
}
3536

37+
IAsyncSubSonicQueryProvider IAsyncSubSonicQueryable<TElement>.AsyncProvider
38+
{
39+
get
40+
{
41+
if (Provider is IAsyncSubSonicQueryProvider provider)
42+
{
43+
return provider;
44+
}
45+
46+
return null;
47+
}
48+
}
49+
3650
#region ICollection<> Implementation
3751
public void Clear()
3852
{
@@ -124,6 +138,11 @@ IEnumerator<TElement> IEnumerable<TElement>.GetEnumerator()
124138
}
125139
}
126140
#endregion
141+
142+
IAsyncEnumerator<TElement> IAsyncEnumerable<TElement>.GetAsyncEnumerator(System.Threading.CancellationToken cancellationToken)
143+
{
144+
throw Error.NotImplemented();
145+
}
127146
}
128147

129148
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1010:Collections should implement generic interface", Justification = "Generic Class that inherits from this one addresses the generic interface")]

SubSonic/Infrastructure/Database/SubSonicTableTypeQueryable.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace SubSonic.Infrastructure
88
{
9+
using Interfaces;
910
using Builders;
1011
using Linq.Expressions;
1112
using Logging;
@@ -33,6 +34,19 @@ public SubSonicTableTypeCollection(string name, IQueryProvider provider, Express
3334

3435
}
3536

37+
public IAsyncSubSonicQueryProvider AsyncProvider
38+
{
39+
get
40+
{
41+
if (Provider is IAsyncSubSonicQueryProvider provider)
42+
{
43+
return provider;
44+
}
45+
46+
return null;
47+
}
48+
}
49+
3650
#region ICollection<> Implementation
3751
public void Clear()
3852
{
@@ -119,6 +133,11 @@ IEnumerator<TElement> IEnumerable<TElement>.GetEnumerator()
119133
}
120134
}
121135
#endregion
136+
137+
IAsyncEnumerator<TElement> IAsyncEnumerable<TElement>.GetAsyncEnumerator(System.Threading.CancellationToken cancellationToken)
138+
{
139+
throw Error.NotImplemented();
140+
}
122141
}
123142

124143
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1010:Collections should implement generic interface", Justification = "Generic Class that inherits from this one addresses the generic interface")]

SubSonic/Infrastructure/DbSetCollection.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace SubSonic.Infrastructure
99
{
10+
using Interfaces;
1011
using Data.Caching;
1112
using Data.DynamicProxies;
1213
using Linq;
@@ -49,6 +50,19 @@ private void OnDbSetCollectionChanged(object sender, NotifyCollectionChangedEven
4950

5051
public IQueryProvider Provider => provider;
5152

53+
public IAsyncSubSonicQueryProvider AsyncProvider
54+
{
55+
get
56+
{
57+
if (this.provider is IAsyncSubSonicQueryProvider @provider)
58+
{
59+
return @provider;
60+
}
61+
62+
return null;
63+
}
64+
}
65+
5266
#region ICollection<TEntity> Implementation
5367
void ISubSonicDbSetCollection.Add(object entity)
5468
{
@@ -152,6 +166,11 @@ IEnumerator<TEntity> IEnumerable<TEntity>.GetEnumerator()
152166
return dataset.Select(x => DynamicProxy.MapInstanceOf(DbContext, x)).GetEnumerator();
153167
}
154168

169+
IAsyncEnumerator<TEntity> IAsyncEnumerable<TEntity>.GetAsyncEnumerator(System.Threading.CancellationToken cancellationToken)
170+
{
171+
throw Error.NotImplemented();
172+
}
173+
155174
public IQueryable Load()
156175
{
157176
Provider.Execute(Expression);

SubSonic/Interfaces/Builders/IDbSqlQueryBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using SubSonic.Infrastructure.Schema;
2+
using SubSonic.Interfaces;
23
using SubSonic.Linq.Expressions;
34
using System;
45
using System.Collections.Generic;
@@ -9,7 +10,7 @@
910
namespace SubSonic.Infrastructure
1011
{
1112
public interface ISubSonicQueryProvider
12-
: IQueryProvider
13+
: IQueryProvider, IAsyncSubSonicQueryProvider
1314
{
1415
DbTableExpression DbTable { get; }
1516

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Linq;
2+
using System.Linq.Expressions;
3+
using System.Threading.Tasks;
4+
5+
namespace SubSonic.Interfaces
6+
{
7+
public interface IAsyncSubSonicQueryProvider
8+
: IQueryProvider
9+
{
10+
/// <summary>
11+
/// Executes the expression asynchronously
12+
/// </summary>
13+
/// <param name="expression"></param>
14+
/// <returns></returns>
15+
Task<object> ExecuteAsync(Expression expression);
16+
/// <summary>
17+
/// Executes the expression asynchronously
18+
/// </summary>
19+
/// <typeparam name="TResult"></typeparam>
20+
/// <param name="Expression"></param>
21+
/// <returns></returns>
22+
Task<TResult> ExecuteAsync<TResult>(Expression Expression);
23+
}
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
4+
namespace SubSonic.Interfaces
5+
{
6+
/// <summary>
7+
///
8+
/// </summary>
9+
/// <typeparam name="TEntity"></typeparam>
10+
public interface IAsyncSubSonicQueryable<out TEntity>
11+
: IQueryable, IEnumerable<TEntity>, IAsyncEnumerable<TEntity>
12+
{
13+
/// <summary>
14+
///
15+
/// </summary>
16+
IAsyncSubSonicQueryProvider AsyncProvider { get; }
17+
}
18+
}

SubSonic/Interfaces/ISubSonicQueryable.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using SubSonic.Interfaces;
2+
using System;
23
using System.Collections;
34
using System.Collections.Generic;
45
using System.ComponentModel;
@@ -16,7 +17,7 @@ public interface ISubSonicDbSetCollection<TEntity>
1617
}
1718

1819
public interface ISubSonicCollection<TEntity>
19-
: ISubSonicCollection, IOrderedQueryable<TEntity>, IQueryable<TEntity>, IEnumerable<TEntity>, IQueryable, IEnumerable, ICollection<TEntity>
20+
: ISubSonicCollection, IOrderedQueryable<TEntity>, IQueryable<TEntity>, IEnumerable<TEntity>, IAsyncSubSonicQueryable<TEntity>, IQueryable, IEnumerable, ICollection<TEntity>
2021
{
2122
void AddRange(IEnumerable<TEntity> entities);
2223
}

0 commit comments

Comments
 (0)