Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions .github/workflows/dotnet-core-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
build:
runs-on: ${{ matrix.os }}
env:
VERSION: 4.1.2
VERSION: 4.2.0-alpha.1
strategy:
matrix:
os: [ubuntu-latest]
Expand All @@ -36,12 +36,6 @@ jobs:
if: matrix.os != 'windows-latest'
run: |
rsync -a ${DOTNET_ROOT/3.1.101/2.2.108}/* $DOTNET_ROOT/
- name: Setup private nuget library
uses: actions/setup-dotnet@v1
with:
source-url: https://nuget.pkg.github.com/subsonic-core/index.json
env:
NUGET_AUTH_TOKEN: ${{secrets.PUBLISH_GITHUB_TOKEN}}
- name: Build with netcoreapp
run: dotnet build --configuration Release
- name: Unit Testing
Expand All @@ -50,5 +44,3 @@ jobs:
run: dotnet pack --configuration Release --output ../nupkgs -p:PackageVersion=${{env.VERSION}} --include-source --include-symbols
- name: Deploy Package Nuget
run: dotnet nuget push -k ${{secrets.NUGET_API_TOKEN}} -s https://www.nuget.org ../nupkgs/*.${{env.VERSION}}.nupkg --skip-duplicate
- name: Deploy Package GitHub Registry
run: dotnet nuget push -k ${{secrets.PUBLISH_GITHUB_TOKEN}} ../nupkgs/*.${{env.VERSION}}.nupkg --skip-duplicate
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "<Pending>")]
public interface ISqlFragment
{
string COALESCE { get; }
string NOT { get; }
string AND { get; }
string AS { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.6" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.6" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.6" />
<PackageReference Include="SubSonic.Core.Abstractions" Version="4.1.2" />
<PackageReference Include="SubSonic.Core.Abstractions" Version="4.2.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
<PackageReference Include="System.Data.Common" Version="4.3.0" />
<PackageReference Condition="'$(TargetFramework)'=='netstandard2.0'" Include="System.Data.DataSetExtensions" Version="4.5.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public DbContextOptionsBuilder RegisterProviderFactory(string providerInvariantN
return this;
}

public void SetServiceProvider(IServiceProvider provider)
public DbContextOptionsBuilder SetServiceProvider(IServiceProvider provider)
{
if (provider is null)
{
Expand All @@ -151,7 +151,7 @@ public void SetServiceProvider(IServiceProvider provider)
SubSonicContext.ServiceProvider = provider;
}

//return this;
return this;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace SubSonic
{
using Linq;
using Schema;
using SubSonic.src;
using Ext = SubSonicExtensions;

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

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

public bool IsReciprocated { get; private set; }

public Type RelatedEntityType { get; private set; }

public Type LookupEntityType { get; private set; }

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

public IDbRelationshipMap RelationshipMap => new DbRelationshipMap(
RelationshipType,
SubSonicContext.DbModel.GetEntityModel(LookupEntityType),
SubSonicContext.DbModel.GetEntityModel(RelatedEntityType),
RelatedKeys.ToArray());
RelationshipType,
SubSonicContext.DbModel.GetEntityModel(LookupEntityType),
SubSonicContext.DbModel.GetEntityModel(RelatedEntityType),
RelatedKeys.ToArray());

public DbNavigationPropertyBuilder<TEntity, TRelatedEntity> WithOne(Expression<Func<TRelatedEntity, TEntity>> selector = null)
public DbNavigationPropertyBuilder<TEntity, TRelatedEntity> WithOne(Expression<Func<TRelatedEntity, TEntity>> selector)
{
if (selector is null)
{
throw Error.ArgumentNull(nameof(selector));
}
if (RelatedEntityType is null)
{
throw Error.InvalidOperation();
}

return new DbNavigationPropertyBuilder<TEntity, TRelatedEntity>(has, nameof(WithOne))
{
RelatedKeys = (selector is null) ? Array.Empty<string>() : GetForeignKeys(selector.Body)
RelatedKeys = GetForeignKeys(selector.Body)
};
}

public DbNavigationPropertyBuilder<TEntity, TRelatedEntity> WithNone()
{
if (RelatedEntityType is null)
{
throw Error.InvalidOperation();
}

return new DbNavigationPropertyBuilder<TEntity, TRelatedEntity>(has, nameof(WithNone))
{
RelatedKeys = GetForeignKeys(typeof(TEntity))
};
}

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

return new DbNavigationPropertyBuilder<TEntity, TRelatedEntity>(has, nameof(WithMany))
{
IsReciprocated = !(selector is null),
LookupEntityType = LookupEntityType,
RelatedKeys = (RelatedKeys?.Any() ?? false) ? RelatedKeys : GetPrimayKeys(selector, LookupEntityType)
};
Expand Down Expand Up @@ -91,11 +112,19 @@ public DbNavigationPropertyBuilder<TEntity, TRelatedEntity> UsingLookup<TLookupE
return this;
}

private string[] GetForeignKeys(Type type)
{
return Ext.GetForeignKeyName(type);
}

private string[] GetForeignKeys(Expression expression)
{
if(expression.IsNotNull())
if(expression is MemberExpression TheMember)
{
return Ext.GetForeignKeyName((PropertyInfo)((MemberExpression)expression).Member);
if (TheMember.Member is PropertyInfo property)
{
return Ext.GetForeignKeyName(property);
}
}
return Array.Empty<string>();
}
Expand All @@ -110,7 +139,7 @@ private string[] GetPrimayKeys(Expression expression, Type lookupEntityType)
}
else
{
return Ext.GetForeignKeyName(lookupEntityType);
return GetForeignKeys(lookupEntityType);
}
}
return Array.Empty<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ private Expression BuildDeleteQuery<TEntity>(IEnumerable<TEntity> entities)

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

MethodInfo method = typeof(Queryable).GetGenericMethod(nameof(Queryable.Where), new[] { DbTable.Type, predicate.GetType() });
MethodInfo method = typeof(Queryable).GetGenericMethod(nameof(Queryable.Where),
new[] { DbTable.Type.GenericTypeArguments[0] },
DbTable.Type,
predicate.GetType());

return DbExpression.DbDelete(
entities,
Expand Down
Loading