Skip to content

Commit 1bd224d

Browse files
authored
Merge pull request #54 from SubSonic-Core/dev/53-Member-Initialization
Dev/53 member initialization
2 parents 559d28d + 0bb261b commit 1bd224d

48 files changed

Lines changed: 1173 additions & 585 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/dotnet-core-release.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
build:
1212
runs-on: ${{ matrix.os }}
1313
env:
14-
VERSION: 4.1.2
14+
VERSION: 4.2.0-alpha.1
1515
strategy:
1616
matrix:
1717
os: [ubuntu-latest]
@@ -36,12 +36,6 @@ jobs:
3636
if: matrix.os != 'windows-latest'
3737
run: |
3838
rsync -a ${DOTNET_ROOT/3.1.101/2.2.108}/* $DOTNET_ROOT/
39-
- name: Setup private nuget library
40-
uses: actions/setup-dotnet@v1
41-
with:
42-
source-url: https://nuget.pkg.github.com/subsonic-core/index.json
43-
env:
44-
NUGET_AUTH_TOKEN: ${{secrets.PUBLISH_GITHUB_TOKEN}}
4539
- name: Build with netcoreapp
4640
run: dotnet build --configuration Release
4741
- name: Unit Testing
@@ -50,5 +44,3 @@ jobs:
5044
run: dotnet pack --configuration Release --output ../nupkgs -p:PackageVersion=${{env.VERSION}} --include-source --include-symbols
5145
- name: Deploy Package Nuget
5246
run: dotnet nuget push -k ${{secrets.NUGET_API_TOKEN}} -s https://www.nuget.org ../nupkgs/*.${{env.VERSION}}.nupkg --skip-duplicate
53-
- name: Deploy Package GitHub Registry
54-
run: dotnet nuget push -k ${{secrets.PUBLISH_GITHUB_TOKEN}} ../nupkgs/*.${{env.VERSION}}.nupkg --skip-duplicate

SubSonic.Core.Abstractions/src/SqlGenerator/ISqlFragment.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "<Pending>")]
55
public interface ISqlFragment
66
{
7+
string COALESCE { get; }
78
string NOT { get; }
89
string AND { get; }
910
string AS { get; }

SubSonic.Core.DataAccessLayer/SubSonic.Core.DataAccessLayer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.6" />
5858
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.6" />
5959
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.6" />
60-
<PackageReference Include="SubSonic.Core.Abstractions" Version="4.1.2" />
60+
<PackageReference Include="SubSonic.Core.Abstractions" Version="4.2.0" />
6161
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
6262
<PackageReference Include="System.Data.Common" Version="4.3.0" />
6363
<PackageReference Condition="'$(TargetFramework)'=='netstandard2.0'" Include="System.Data.DataSetExtensions" Version="4.5.0" />

SubSonic.Core.DataAccessLayer/src/Builders/DbContextOptionsBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public DbContextOptionsBuilder RegisterProviderFactory(string providerInvariantN
139139
return this;
140140
}
141141

142-
public void SetServiceProvider(IServiceProvider provider)
142+
public DbContextOptionsBuilder SetServiceProvider(IServiceProvider provider)
143143
{
144144
if (provider is null)
145145
{
@@ -151,7 +151,7 @@ public void SetServiceProvider(IServiceProvider provider)
151151
SubSonicContext.ServiceProvider = provider;
152152
}
153153

154-
//return this;
154+
return this;
155155
}
156156
}
157157
}

SubSonic.Core.DataAccessLayer/src/Builders/DbNavigationPropertyBuilder.cs

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace SubSonic
88
{
99
using Linq;
1010
using Schema;
11+
using SubSonic.src;
1112
using Ext = SubSonicExtensions;
1213

1314
public class DbNavigationPropertyBuilder<TEntity, TRelatedEntity>
@@ -30,28 +31,47 @@ public DbNavigationPropertyBuilder(string has, string with)
3031

3132
public DbRelationshipType RelationshipType => (DbRelationshipType)Enum.Parse(typeof(DbRelationshipType), $"{has}{with}");
3233

34+
public bool IsReciprocated { get; private set; }
35+
3336
public Type RelatedEntityType { get; private set; }
3437

3538
public Type LookupEntityType { get; private set; }
3639

3740
public IEnumerable<string> RelatedKeys { get; private set; }
3841

3942
public IDbRelationshipMap RelationshipMap => new DbRelationshipMap(
40-
RelationshipType,
41-
SubSonicContext.DbModel.GetEntityModel(LookupEntityType),
42-
SubSonicContext.DbModel.GetEntityModel(RelatedEntityType),
43-
RelatedKeys.ToArray());
43+
RelationshipType,
44+
SubSonicContext.DbModel.GetEntityModel(LookupEntityType),
45+
SubSonicContext.DbModel.GetEntityModel(RelatedEntityType),
46+
RelatedKeys.ToArray());
4447

45-
public DbNavigationPropertyBuilder<TEntity, TRelatedEntity> WithOne(Expression<Func<TRelatedEntity, TEntity>> selector = null)
48+
public DbNavigationPropertyBuilder<TEntity, TRelatedEntity> WithOne(Expression<Func<TRelatedEntity, TEntity>> selector)
4649
{
50+
if (selector is null)
51+
{
52+
throw Error.ArgumentNull(nameof(selector));
53+
}
4754
if (RelatedEntityType is null)
4855
{
4956
throw Error.InvalidOperation();
5057
}
5158

5259
return new DbNavigationPropertyBuilder<TEntity, TRelatedEntity>(has, nameof(WithOne))
5360
{
54-
RelatedKeys = (selector is null) ? Array.Empty<string>() : GetForeignKeys(selector.Body)
61+
RelatedKeys = GetForeignKeys(selector.Body)
62+
};
63+
}
64+
65+
public DbNavigationPropertyBuilder<TEntity, TRelatedEntity> WithNone()
66+
{
67+
if (RelatedEntityType is null)
68+
{
69+
throw Error.InvalidOperation();
70+
}
71+
72+
return new DbNavigationPropertyBuilder<TEntity, TRelatedEntity>(has, nameof(WithNone))
73+
{
74+
RelatedKeys = GetForeignKeys(typeof(TEntity))
5575
};
5676
}
5777

@@ -64,6 +84,7 @@ public DbNavigationPropertyBuilder<TEntity, TRelatedEntity> WithMany(Expression<
6484

6585
return new DbNavigationPropertyBuilder<TEntity, TRelatedEntity>(has, nameof(WithMany))
6686
{
87+
IsReciprocated = !(selector is null),
6788
LookupEntityType = LookupEntityType,
6889
RelatedKeys = (RelatedKeys?.Any() ?? false) ? RelatedKeys : GetPrimayKeys(selector, LookupEntityType)
6990
};
@@ -91,11 +112,19 @@ public DbNavigationPropertyBuilder<TEntity, TRelatedEntity> UsingLookup<TLookupE
91112
return this;
92113
}
93114

115+
private string[] GetForeignKeys(Type type)
116+
{
117+
return Ext.GetForeignKeyName(type);
118+
}
119+
94120
private string[] GetForeignKeys(Expression expression)
95121
{
96-
if(expression.IsNotNull())
122+
if(expression is MemberExpression TheMember)
97123
{
98-
return Ext.GetForeignKeyName((PropertyInfo)((MemberExpression)expression).Member);
124+
if (TheMember.Member is PropertyInfo property)
125+
{
126+
return Ext.GetForeignKeyName(property);
127+
}
99128
}
100129
return Array.Empty<string>();
101130
}
@@ -110,7 +139,7 @@ private string[] GetPrimayKeys(Expression expression, Type lookupEntityType)
110139
}
111140
else
112141
{
113-
return Ext.GetForeignKeyName(lookupEntityType);
142+
return GetForeignKeys(lookupEntityType);
114143
}
115144
}
116145
return Array.Empty<string>();

SubSonic.Core.DataAccessLayer/src/Builders/DbSqlQueryBuilder/DbSqlQueryBuilder.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ private Expression BuildDeleteQuery<TEntity>(IEnumerable<TEntity> entities)
151151

152152
predicate = (LambdaExpression)BuildLambda(logical, LambdaType.Predicate);
153153

154-
MethodInfo method = typeof(Queryable).GetGenericMethod(nameof(Queryable.Where), new[] { DbTable.Type, predicate.GetType() });
154+
MethodInfo method = typeof(Queryable).GetGenericMethod(nameof(Queryable.Where),
155+
new[] { DbTable.Type.GenericTypeArguments[0] },
156+
DbTable.Type,
157+
predicate.GetType());
155158

156159
return DbExpression.DbDelete(
157160
entities,

0 commit comments

Comments
 (0)