Skip to content

Commit

Permalink
Merge pull request #140 from linq2db/version3
Browse files Browse the repository at this point in the history
Release 3.10.1
  • Loading branch information
sdanyliv authored Apr 30, 2021
2 parents f9f9bd3 + f62c96f commit e7078cf
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Build/linq2db.Default.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>3.10.0</Version>
<Version>3.10.1</Version>

<Authors>Svyatoslav Danyliv, Igor Tkachev, Dmitry Lukashenko, Ilya Chudin</Authors>
<Product>Linq to DB</Product>
Expand Down
16 changes: 12 additions & 4 deletions Source/LinqToDB.EntityFrameworkCore/LinqToDBExtensionsAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,21 @@ public Task<TSource> FirstAsync<TSource>(
=> EntityFrameworkQueryableExtensions.FirstAsync(source, predicate, token);

/// <inheritdoc cref="EntityFrameworkQueryableExtensions.FirstOrDefaultAsync{TSource}(IQueryable{TSource}, CancellationToken)"/>
public Task<TSource> FirstOrDefaultAsync<TSource>(
public Task<TSource?> FirstOrDefaultAsync<TSource>(
IQueryable<TSource> source,
CancellationToken token)
#pragma warning disable CS8619 // Nullability of reference types in value doesn't match target type.
=> EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(source, token);
#pragma warning restore CS8619 // Nullability of reference types in value doesn't match target type.

/// <inheritdoc cref="EntityFrameworkQueryableExtensions.FirstOrDefaultAsync{TSource}(IQueryable{TSource}, Expression{Func{TSource, bool}}, CancellationToken)"/>
public Task<TSource> FirstOrDefaultAsync<TSource>(
public Task<TSource?> FirstOrDefaultAsync<TSource>(
IQueryable<TSource> source,
Expression<Func<TSource,bool>> predicate,
CancellationToken token)
#pragma warning disable CS8619 // Nullability of reference types in value doesn't match target type.
=> EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(source, predicate, token);
#pragma warning restore CS8619 // Nullability of reference types in value doesn't match target type.

/// <inheritdoc cref="EntityFrameworkQueryableExtensions.SingleAsync{TSource}(IQueryable{TSource}, CancellationToken)"/>
public Task<TSource> SingleAsync<TSource>(
Expand All @@ -113,17 +117,21 @@ public Task<TSource> SingleAsync<TSource>(
=> EntityFrameworkQueryableExtensions.SingleAsync(source, predicate, token);

/// <inheritdoc cref="EntityFrameworkQueryableExtensions.SingleOrDefaultAsync{TSource}(IQueryable{TSource}, CancellationToken)"/>
public Task<TSource> SingleOrDefaultAsync<TSource>(
public Task<TSource?> SingleOrDefaultAsync<TSource>(
IQueryable<TSource> source,
CancellationToken token)
#pragma warning disable CS8619 // Nullability of reference types in value doesn't match target type.
=> EntityFrameworkQueryableExtensions.SingleOrDefaultAsync(source, token);
#pragma warning restore CS8619 // Nullability of reference types in value doesn't match target type.

/// <inheritdoc cref="EntityFrameworkQueryableExtensions.SingleOrDefaultAsync{TSource}(IQueryable{TSource}, Expression{Func{TSource, bool}}, CancellationToken)"/>
public Task<TSource> SingleOrDefaultAsync<TSource>(
public Task<TSource?> SingleOrDefaultAsync<TSource>(
IQueryable<TSource> source,
Expression<Func<TSource,bool>> predicate,
CancellationToken token)
#pragma warning disable CS8619 // Nullability of reference types in value doesn't match target type.
=> EntityFrameworkQueryableExtensions.SingleOrDefaultAsync(source, predicate, token);
#pragma warning restore CS8619 // Nullability of reference types in value doesn't match target type.

/// <inheritdoc cref="EntityFrameworkQueryableExtensions.ContainsAsync{TSource}(IQueryable{TSource}, TSource, CancellationToken)"/>
public Task<bool> ContainsAsync<TSource>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ public static Task<TSource> FirstAsyncLinqToDB<TSource>(
=> AsyncExtensions.FirstAsync(source.ToLinqToDB(), predicate, token);

/// <inheritdoc cref="AsyncExtensions.FirstOrDefaultAsync{TSource}(IQueryable{TSource}, CancellationToken)"/>
public static Task<TSource> FirstOrDefaultAsyncLinqToDB<TSource>(
public static Task<TSource?> FirstOrDefaultAsyncLinqToDB<TSource>(
this IQueryable<TSource> source,
CancellationToken token = default)
=> AsyncExtensions.FirstOrDefaultAsync(source.ToLinqToDB(), token);

/// <inheritdoc cref="AsyncExtensions.FirstOrDefaultAsync{TSource}(IQueryable{TSource}, Expression{Func{TSource, bool}}, CancellationToken)"/>
public static Task<TSource> FirstOrDefaultAsyncLinqToDB<TSource>(
public static Task<TSource?> FirstOrDefaultAsyncLinqToDB<TSource>(
this IQueryable<TSource> source,
Expression<Func<TSource,bool>> predicate,
CancellationToken token = default)
Expand All @@ -102,13 +102,13 @@ public static Task<TSource> SingleAsyncLinqToDB<TSource>(
=> AsyncExtensions.SingleAsync(source.ToLinqToDB(), predicate, token);

/// <inheritdoc cref="AsyncExtensions.SingleOrDefaultAsync{TSource}(IQueryable{TSource}, CancellationToken)"/>
public static Task<TSource> SingleOrDefaultAsyncLinqToDB<TSource>(
public static Task<TSource?> SingleOrDefaultAsyncLinqToDB<TSource>(
this IQueryable<TSource> source,
CancellationToken token = default)
=> AsyncExtensions.SingleOrDefaultAsync(source.ToLinqToDB(), token);

/// <inheritdoc cref="AsyncExtensions.SingleOrDefaultAsync{TSource}(IQueryable{TSource}, Expression{Func{TSource, bool}}, CancellationToken)"/>
public static Task<TSource> SingleOrDefaultAsyncLinqToDB<TSource>(
public static Task<TSource?> SingleOrDefaultAsyncLinqToDB<TSource>(
this IQueryable<TSource> source,
Expression<Func<TSource,bool>> predicate,
CancellationToken token = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ public static async Task<BulkCopyRowsCopied> BulkCopyAsync<T>(
[LinqTunnel]
[Pure]
public static IValueInsertable<T> Into<T>(this DbContext context, ITable<T> target)
where T: notnull
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (target == null) throw new ArgumentNullException(nameof(target));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ protected virtual IDataProvider CreateSqlServerProvider(SqlServerVersion version
{
providerName = "Microsoft.Data.SqlClient";

return DataConnection.GetDataProvider(providerName, connectionString)!;
return DataConnection.GetDataProvider(providerName, connectionString!)!;
}

switch (version)
Expand Down Expand Up @@ -364,7 +364,7 @@ protected virtual IDataProvider CreateSqlServerProvider(SqlServerVersion version
protected virtual IDataProvider CreatePostgreSqlProvider(PostgreSQLVersion version, string? connectionString)
{
if (!string.IsNullOrEmpty(connectionString))
return DataConnection.GetDataProvider(ProviderName.PostgreSQL, connectionString)!;
return DataConnection.GetDataProvider(ProviderName.PostgreSQL, connectionString!)!;

string providerName;
switch (version)
Expand Down Expand Up @@ -450,6 +450,10 @@ public virtual void DefineConvertors(
if (modelType.IsEnum)
continue;

// skipping arrays
if (modelType.IsArray)
continue;

MapEFCoreType(modelType);
if (modelType.IsValueType && !typeof(Nullable<>).IsSameOrParentOf(modelType))
MapEFCoreType(typeof(Nullable<>).MakeGenericType(modelType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,19 @@
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
<DebugType>portable</DebugType>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="linq2db" Version="3.3.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.11" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<PackageReference Include="linq2db.Tools" Version="3.2.3" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.11" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.11" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.11" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ internal class TestLogger : ILogger
private static readonly string _newLineWithMessagePadding;

// ConsoleColor does not have a value to specify the 'Default' color
#pragma warning disable 649
private readonly ConsoleColor? DefaultConsoleColor;
#pragma warning restore 649

private readonly string _name;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.ComponentModel.DataAnnotations;

namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.Models.NpgSqlEntities
{
public class EntityWithArrays
{
[Key]
public int Id { get; set; }

public Guid[] Guids { get; set; } = null!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
entity.HasNoKey();
entity.ToView("EventsView", "views");
});

modelBuilder.Entity<EntityWithArrays>(entity =>
{
});
}

public virtual DbSet<Event> Events { get; set; } = null!;
public virtual DbSet<EntityWithArrays> EntityWithArrays { get; set; } = null!;

}
}
39 changes: 36 additions & 3 deletions Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/NpgSqlTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Linq;
using FluentAssertions;
using LinqToDB.Data;
using LinqToDB.DataProvider.PostgreSQL;
using LinqToDB.EntityFrameworkCore.BaseTests;
using LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.Models.NpgSqlEntities;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -29,19 +31,21 @@ public NpgSqlTests()
_options = optionsBuilder.Options;
}

private NpgSqlEnititesContext CreateNpgSqlExntitiesContext()
private NpgSqlEnititesContext CreateNpgSqlEntitiesContext()
{
var ctx = new NpgSqlEnititesContext(_options);
ctx.Database.EnsureDeleted();
ctx.Database.EnsureCreated();
ctx.Database.ExecuteSqlRaw("create schema \"views\"");
ctx.Database.ExecuteSqlRaw("create view \"views\".\"EventsView\" as select \"Name\" from \"Events\"");
return ctx;
}


[Test]
public void TestFunctionsMapping()
{
using (var db = CreateNpgSqlExntitiesContext())
using (var db = CreateNpgSqlEntitiesContext())
{
var date = DateTime.UtcNow;

Expand All @@ -54,6 +58,35 @@ public void TestFunctionsMapping()
}
}


[Test]
public void TestViewMapping()
{
using (var db = CreateNpgSqlEntitiesContext())
{
var query = db.Set<EventView>().Where(e =>
e.Name.StartsWith("any"));

var efResult = query.ToArray();
var l2dbResult = query.ToLinqToDB().ToArray();
}
}

[Test]
public void TestArray()
{
using (var db = CreateNpgSqlEntitiesContext())
{
var guids = new Guid[] { Guid.Parse("271425b1-ebe8-400d-b71d-a6e47a460ae3"),
Guid.Parse("b75de94e-6d7b-4c70-bfa1-f8639a6a5b35") };

var query =
from m in db.EntityWithArrays.ToLinqToDBTable()
where Sql.Ext.PostgreSQL().Overlaps(m.Guids, guids)
select m;

query.Invoking(q => q.ToArray()).Should().NotThrow();
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Threading.Tasks;

#pragma warning disable 8604
#pragma warning disable CS8625

namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.SampleTests
{
public class Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace LinqToDB.EntityFrameworkCore.SqlServer.Tests
[TestFixture]
public class IssueTests : TestsBase
{
private DbContextOptions<IssueContext>? _options;
private DbContextOptions<IssueContext> _options = null!;
private bool _created;

public IssueTests()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder
.Entity<Patent>()
.HasOne(p => p.Assessment)
.WithOne(pa => pa.Patent)
.WithOne(pa => pa!.Patent)
.HasForeignKey<PatentAssessment>(pa => pa.PatentId)
.OnDelete(DeleteBehavior.Restrict);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ public async Task TestSetUpdate([Values(true, false)] bool enableFilter)
{
using (var ctx = CreateContext(enableFilter))
{
var customer = await ctx.Customers.FirstOrDefaultAsync();
var customer = await ctx.Customers.FirstAsync();

var updatable = ctx.Customers.Where(c => c.CustomerId == customer.CustomerId)
.Set(c => c.CompanyName, customer.CompanyName);
Expand Down
21 changes: 16 additions & 5 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
variables:
solution: 'linq2db.EFCore.sln'
build_configuration: 'Release'
assemblyVersion: 3.10.0
nugetVersion: 3.10.0
assemblyVersion: 3.10.1
nugetVersion: 3.10.1
artifact_nugets: 'nugets'

# build on commits to important branches (master + release branches):
Expand Down Expand Up @@ -44,37 +44,48 @@ stages:
inputs:
solution: '$(solution)'
configuration: '$(build_configuration)'
msbuildArguments: '/t:Restore;Rebuild -m'
msbuildArguments: '/t:Restore;Rebuild -m /p:ContinuousIntegrationBuild=true'
displayName: Build Solution

- powershell: echo "##vso[task.setvariable variable=packageVersion]$(packageVersion)-rc.$(Build.BuildId)"
condition: ne(variables['Build.SourceBranchName'], 'release.3')
displayName: Set nuget RC version for non-release branch
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'version3'))

- task: PowerShell@2
inputs:
filePath: '$(Build.SourcesDirectory)/NuGet/BuildNuspecs.ps1'
workingDirectory: '$(Build.SourcesDirectory)'
arguments: -path $(Build.SourcesDirectory)/NuGet/linq2db.EntityFrameworkCore.nuspec -version $(packageVersion) -branch $(Build.SourceBranchName)
displayName: Generate nuspec
condition: and(succeeded(), or(eq(variables['Build.SourceBranchName'], 'release.3'), eq(variables['Build.SourceBranchName'], 'version3')))

- task: NuGetToolInstaller@0
inputs:
versionSpec: '5.x'
workingDirectory: $(Build.SourcesDirectory)/NuGet
displayName: Install nuget
condition: and(succeeded(), or(eq(variables['Build.SourceBranchName'], 'release.3'), eq(variables['Build.SourceBranchName'], 'version3')))

- task: CmdLine@2
inputs:
script: 'nuget Pack linq2db.EntityFrameworkCore.nuspec -OutputDirectory built'
workingDirectory: $(Build.SourcesDirectory)/NuGet
displayName: Build nuget
displayName: Build nuget (azure artifacts)
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'version3'))

- task: CmdLine@2
inputs:
script: 'nuget Pack linq2db.EntityFrameworkCore.nuspec -OutputDirectory built -Symbols -SymbolPackageFormat snupkg'
workingDirectory: $(Build.SourcesDirectory)/NuGet
displayName: Build nuget (nuget.org)
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'release.3'))

- task: PublishBuildArtifacts@1
inputs:
pathToPublish: '$(Build.SourcesDirectory)/NuGet/built'
artifactName: '$(artifact_nugets)'
displayName: Publish nugets to artifacts
condition: and(succeeded(), or(eq(variables['Build.SourceBranchName'], 'release.3'), eq(variables['Build.SourceBranchName'], 'version3')))

- task: NuGetCommand@2
inputs:
Expand Down

0 comments on commit e7078cf

Please sign in to comment.