Skip to content

Commit f651b8a

Browse files
committed
Merge branch 'hotfix/2.0.2'
2 parents 5b83332 + 3b6fbd9 commit f651b8a

15 files changed

Lines changed: 67 additions & 27 deletions

.appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
image: Visual Studio 2017 Preview
2-
version: 2.0.1-{build}
2+
version: 2.0.2-{build}
33
services:
44
- postgresql
55
environment:
@@ -30,7 +30,7 @@ artifacts:
3030
- path: 'src\EFCore.PG\bin\**\*.nupkg'
3131
deploy:
3232
- provider: NuGet
33-
server: https://www.myget.org/F/npgsql-unstable/api/v2/package
33+
server: https://www.myget.org/F/npgsql/api/v2/package
3434
api_key:
3535
secure: kiMn9uBvgMa5EtEmTIhNBFUfyatiATnhkgx5Xj/1EsmKTtEkUv+hJAQs0L3VGzPw
3636
artifact: /.*\.nupkg/

src/EFCore.PG/EFCore.PG.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VersionPrefix>2.0.1</VersionPrefix>
4+
<VersionPrefix>2.0.2</VersionPrefix>
55
<TargetFrameworks>netstandard2.0</TargetFrameworks>
66
<AssemblyName>Npgsql.EntityFrameworkCore.PostgreSQL</AssemblyName>
77
<RootNamespace>Microsoft.EntityFrameworkCore</RootNamespace>
@@ -25,11 +25,11 @@
2525
</ItemGroup>
2626

2727
<ItemGroup>
28-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.1" />
29-
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.0.1" />
28+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.2" />
29+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.0.2" />
3030
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.0.0" />
3131
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
32-
<PackageReference Include="Npgsql" Version="3.2.5" />
32+
<PackageReference Include="Npgsql" Version="3.2.7" />
3333
</ItemGroup>
3434

3535
</Project>

src/EFCore.PG/Metadata/INpgsqlEntityTypeAnnotations.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ public interface INpgsqlEntityTypeAnnotations : IRelationalEntityTypeAnnotations
77
bool SetStorageParameter(string parameterName, object parameterValue);
88
Dictionary<string, object> GetStorageParameters();
99
string Comment { get; }
10+
CockroachDbInterleaveInParent CockroachDbInterleaveInParent { get; }
1011
}
1112
}

src/EFCore.PG/Migrations/Internal/NpgsqlMigrationsAnnotationProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public override IEnumerable<IAnnotation> For(IEntityType entityType)
4242
{
4343
if (entityType.Npgsql().Comment != null)
4444
yield return new Annotation(NpgsqlAnnotationNames.Comment, entityType.Npgsql().Comment);
45+
if (entityType[CockroachDbAnnotationNames.InterleaveInParent] != null)
46+
yield return new Annotation(CockroachDbAnnotationNames.InterleaveInParent, entityType[CockroachDbAnnotationNames.InterleaveInParent]);
4547
foreach (var storageParamAnnotation in entityType.GetAnnotations()
4648
.Where(a => a.Name.StartsWith(NpgsqlAnnotationNames.StorageParameterPrefix)))
4749
{

src/EFCore.PG/Migrations/NpgsqlMigrationsSqlGenerator.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ protected override void Generate(
9191
base.Generate(operation, model, builder, false);
9292

9393
// CockroachDB "interleave in parent" (https://www.cockroachlabs.com/docs/stable/interleave-in-parent.html)
94-
var interleaveInParentStr = operation[CockroachDbAnnotationNames.InterleaveInParent] as string;
95-
if (interleaveInParentStr != null)
94+
if (operation[CockroachDbAnnotationNames.InterleaveInParent] is string)
9695
{
9796
var interleaveInParent = new CockroachDbInterleaveInParent(operation);
9897
var parentTableSchema = interleaveInParent.ParentTableSchema;
@@ -518,6 +517,13 @@ protected override void Generate(
518517
.Append(ColumnList(operation.Columns))
519518
.Append(")");
520519

520+
if (!string.IsNullOrEmpty(operation.Filter))
521+
{
522+
builder
523+
.Append(" WHERE ")
524+
.Append(operation.Filter);
525+
}
526+
521527
builder.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);
522528

523529
EndStatement(builder);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Data;
3+
using JetBrains.Annotations;
4+
5+
namespace Microsoft.EntityFrameworkCore.Storage.Internal
6+
{
7+
public class NpgsqlTimeSpanTypeMapping : NpgsqlTypeMapping
8+
{
9+
public NpgsqlTimeSpanTypeMapping()
10+
: base("interval", typeof(TimeSpan), NpgsqlTypes.NpgsqlDbType.Interval)
11+
{
12+
}
13+
14+
public override RelationalTypeMapping Clone(string storeType, int? size)
15+
=> new NpgsqlTimeSpanTypeMapping();
16+
17+
protected override string GenerateNonNullSqlLiteral(object value)
18+
{
19+
var ts = (TimeSpan)value;
20+
return $"INTERVAL '{ts.ToString($@"{(ts < TimeSpan.Zero ? "\\-" : "")}{(ts.Days == 0 ? "" : "d\\ ")}hh\:mm\:ss{(ts.Milliseconds == 0 ? "" : $"\\.FFF")}")}'";
21+
}
22+
}
23+
}

src/EFCore.PG/Storage/Internal/NpgsqlDatabaseCreator.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,15 @@ public override void CreateTables()
240240

241241
if (reloadTypes)
242242
{
243-
var npgsqlConn = (NpgsqlConnection)_connection.DbConnection;
244-
if (npgsqlConn.FullState == ConnectionState.Open)
245-
npgsqlConn.ReloadTypes();
243+
_connection.Open();
244+
try
245+
{
246+
((NpgsqlConnection)_connection.DbConnection).ReloadTypes();
247+
}
248+
catch
249+
{
250+
_connection.Close();
251+
}
246252
}
247253
}
248254

src/EFCore.PG/Storage/Internal/NpgsqlEFTypeMapper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,15 @@ void AddCustomizedMappings()
8181
// Mappings where we need literal string generation
8282
_baseClrMappings[typeof(string)] = _storeTypeMappings["text"] = new NpgsqlStringTypeMapping("text", NpgsqlDbType.Text);
8383
_storeTypeMappings["varchar"] = new NpgsqlStringTypeMapping("varchar", NpgsqlDbType.Varchar);
84+
_storeTypeMappings["char"] = new NpgsqlStringTypeMapping("char", NpgsqlDbType.Char);
8485
_storeTypeMappings["citext"] = new NpgsqlStringTypeMapping("citext", NpgsqlDbType.Citext);
8586
_storeTypeMappings["json"] = new NpgsqlStringTypeMapping("json", NpgsqlDbType.Json);
8687
_storeTypeMappings["jsonb"] = new NpgsqlStringTypeMapping("jsonb", NpgsqlDbType.Jsonb);
8788

8889
_baseClrMappings[typeof(char)] = new CharTypeMapping("text", DbType.String);
8990
_baseClrMappings[typeof(DateTime)] = _storeTypeMappings["timestamp"] = new DateTimeTypeMapping("timestamp", DbType.DateTime);
9091
_baseClrMappings[typeof(DateTimeOffset)] = _storeTypeMappings["timestamptz"] = new NpgsqlDateTimeOffsetTypeMapping("timestamptz", DbType.DateTimeOffset);
92+
_baseClrMappings[typeof(TimeSpan)] = _storeTypeMappings["interval"] = new NpgsqlTimeSpanTypeMapping();
9193
_baseClrMappings[typeof(bool)] = _storeTypeMappings["bool"] = new NpgsqlBoolTypeMapping();
9294

9395
_baseClrMappings[typeof(decimal)] = new DecimalTypeMapping("numeric", DbType.Decimal);

src/EFCore.PG/Storage/NpgsqlStringRelationalTypeMapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Storage
3131
public class NpgsqlStringRelationalTypeMapper : IStringRelationalTypeMapper
3232
{
3333
static readonly RelationalTypeMapping UnboundedStringMapping
34-
= new NpgsqlTypeMapping("text", typeof(string), NpgsqlDbType.Text);
34+
= new NpgsqlStringTypeMapping("text", NpgsqlDbType.Text);
3535

3636
readonly ConcurrentDictionary<int, RelationalTypeMapping> _boundedStringMappings
3737
= new ConcurrentDictionary<int, RelationalTypeMapping>();
@@ -40,7 +40,7 @@ public RelationalTypeMapping FindMapping(bool unicode, bool keyOrIndex, int? max
4040
{
4141
return maxLength.HasValue
4242
? _boundedStringMappings.GetOrAdd(maxLength.Value,
43-
ml => new NpgsqlTypeMapping($"varchar({maxLength})", typeof(string))
43+
ml => new NpgsqlStringTypeMapping($"varchar({maxLength})", NpgsqlDbType.Varchar)
4444
)
4545
: UnboundedStringMapping;
4646
}

test/EFCore.PG.Design.FunctionalTests/EFCore.PG.Design.FunctionalTests.csproj

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

2222
<ItemGroup>
2323
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
24-
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational.Design.Specification.Tests" Version="2.0.1" />
24+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational.Design.Specification.Tests" Version="2.0.2" />
2525
</ItemGroup>
2626

2727
</Project>

0 commit comments

Comments
 (0)