Skip to content

Commit d25b1eb

Browse files
committed
#53 extension method being mapped by compiler that should not be.
1 parent bd02ee8 commit d25b1eb

File tree

8 files changed

+46
-42
lines changed

8 files changed

+46
-42
lines changed

SubSonic.Core.DataAccessLayer/src/Data/ChangeTracking/ChangeTrackerCollection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,14 @@ private IEnumerable<KeyValuePair<Type, IEnumerable<IEntityProxy>>> BuildEnumerat
178178
case DbQueryType.Insert:
179179
return collection
180180
.OrderBy(x => x.Value.Model.ObjectGraphWeight)
181-
.Select(set => new KeyValuePair<Type, IEnumerable<IEntityProxy>>(set.Key, set.Value.Select(x => (IEntityProxy)x)));
181+
.Select(set => new KeyValuePair<Type, IEnumerable<IEntityProxy>>(set.Key, set.Value.ToProxyCollection()));
182182
case DbQueryType.Delete:
183183
return collection
184184
.OrderByDescending(x => x.Value.Model.ObjectGraphWeight)
185-
.Select(set => new KeyValuePair<Type, IEnumerable<IEntityProxy>>(set.Key, set.Value.Select(x => (IEntityProxy)x)));
185+
.Select(set => new KeyValuePair<Type, IEnumerable<IEntityProxy>>(set.Key, set.Value.ToProxyCollection()));
186186
case DbQueryType.Unknown:
187187
return collection
188-
.Select(set => new KeyValuePair<Type, IEnumerable<IEntityProxy>>(set.Key, set.Value.Select(x => (IEntityProxy)x)));
188+
.Select(set => new KeyValuePair<Type, IEnumerable<IEntityProxy>>(set.Key, set.Value.ToProxyCollection()));
189189
}
190190
throw Error.NotSupported();
191191
}

SubSonic.Core.DataAccessLayer/src/Data/ChangeTracking/ChangeTrackerElement.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,23 @@ public void Clear()
298298
((IList)Cache).Clear();
299299
}
300300

301+
public IEnumerable<IEntityProxy> ToProxyCollection()
302+
{
303+
IList<IEntityProxy> proxies = new List<IEntityProxy>();
304+
305+
foreach(IEntityProxy proxy in Cache)
306+
{
307+
if (proxy is null)
308+
{
309+
throw Error.InvalidOperation();
310+
}
311+
312+
proxies.Add(proxy);
313+
}
314+
315+
return proxies;
316+
}
317+
301318
public abstract void Add(object record);
302319

303320
public abstract bool Remove(object record);

SubSonic.Core.DataAccessLayer/src/Linq/Extensions/SubSonicQueryable/EnumerableExtensions.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,5 @@ public static IQueryable<TSource> ForEach<TSource>(this IQueryable<TSource> sour
3434

3535
return source;
3636
}
37-
38-
public static IEnumerable<TResult> Select<TResult>(this IEnumerable source, Func<object, TResult> selector)
39-
{
40-
if (source is null)
41-
{
42-
throw new ArgumentNullException(nameof(source));
43-
}
44-
45-
if (selector is null)
46-
{
47-
throw new ArgumentNullException(nameof(selector));
48-
}
49-
50-
List<TResult> result = new List<TResult>();
51-
52-
foreach(object item in source)
53-
{
54-
result.Add(selector(item));
55-
}
56-
57-
return result;
58-
}
5937
}
6038
}

SubSonic.Extensions.SqlServer/SubSonic.Extensions.SqlServer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
<ItemGroup>
3131
<PackageReference Include="Microsoft.Data.SqlClient" Version="2.0.0" />
32-
<PackageReference Include="SubSonic.Core.DAL" Version="4.1.1" />
32+
<PackageReference Include="SubSonic.Core.DAL" Version="4.1.2" />
3333
</ItemGroup>
3434

3535
<ItemGroup>

SubSonic.Tests/DAL/ExtensionMethod/IncludeExtensionMethodTests.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
using FluentAssertions;
2+
using Microsoft.Extensions.Logging;
23
using NUnit.Framework;
4+
using SubSonic.Extensions.Test;
5+
using SubSonic.Linq;
6+
using SubSonic.Logging;
37
using System;
48
using System.Linq;
59

610
namespace SubSonic.Tests.DAL.ExtensionMethod
711
{
8-
using Linq;
9-
using Microsoft.Extensions.Logging;
10-
using SubSonic.Extensions.Test;
11-
using SubSonic.Extensions.Test.Models;
12-
using SubSonic.Logging;
13-
using System.Threading.Tasks;
14-
using Models = Extensions.Test.Models;
15-
16-
1712
public partial class ExtensionMethodTests
1813
{
1914
[Test]

SubSonic.Tests/DAL/SubSonicContext/DbDeleteTests.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,16 @@ SELECT [T3].[UnitID]
8181
[TestCaseSource(nameof(DeleteTestCases))]
8282
public void ShouldBeAbleToDeleteOneOrMoreRecords(IDbTestCase dbTest)
8383
{
84-
IEnumerable<IEntityProxy>
85-
expected = dbTest.FetchAll().Select(x =>
86-
x as IEntityProxy);
84+
IList<IEntityProxy>
85+
expected = new List<IEntityProxy>();
86+
87+
foreach (IEntityProxy proxy in dbTest.FetchAll())
88+
{
89+
if (proxy != null)
90+
{
91+
expected.Add(proxy);
92+
}
93+
}
8794

8895
int
8996
before = dbTest.Count(),

SubSonic.Tests/DAL/SubSonicContext/DbUpdateTests.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,16 @@ FROM [dbo].[Renter] AS [T1]
5959
[TestCaseSource(nameof(UpdateTestCases))]
6060
public void CanUpdateEntities(IDbTestCase dbTest)
6161
{
62-
IEnumerable<IEntityProxy>
63-
expected = dbTest.FetchAll().Select(x =>
64-
x as IEntityProxy);
62+
IList<IEntityProxy>
63+
expected = new List<IEntityProxy>();
64+
65+
foreach (IEntityProxy proxy in dbTest.FetchAll())
66+
{
67+
if (proxy != null)
68+
{
69+
expected.Add(proxy);
70+
}
71+
}
6572

6673
expected.Count().Should().Be(dbTest.Count());
6774

SubSonic.Tests/SubSonic.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</PackageReference>
2222
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
2323
<PackageReference Include="SubSonic.Core.Abstractions" Version="4.2.0" />
24-
<PackageReference Include="SubSonic.Extensions.SqlServer" Version="4.2.0" />
24+
<PackageReference Include="SubSonic.Extensions.SqlServer" Version="4.2.1" />
2525
<PackageReference Include="SubSonic.Extensions.Test" Version="4.2.1" />
2626
</ItemGroup>
2727

0 commit comments

Comments
 (0)