-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
378 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"sdk": { | ||
"version": "5.0.103" | ||
"version": "5.0.103", | ||
"rollForward": "latestFeature" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
samples/EFCore.Cassandra.Samples/Migrations/20210919135929_NullableInteger.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
samples/EFCore.Cassandra.Samples/Migrations/20210919135929_NullableInteger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
namespace EFCore.Cassandra.Samples.Migrations | ||
{ | ||
public partial class NullableInteger : Migration | ||
{ | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.EnsureSchema( | ||
name: "cv"); | ||
|
||
migrationBuilder.AddColumn<int>( | ||
name: "NullableInteger", | ||
schema: "cv", | ||
table: "applicants", | ||
type: "int", | ||
nullable: true); | ||
} | ||
|
||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropColumn( | ||
name: "NullableInteger", | ||
schema: "cv", | ||
table: "applicants"); | ||
|
||
migrationBuilder.EnsureSchema( | ||
name: "cv"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) SimpleIdServer. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
using System; | ||
using System.Data; | ||
using System.Data.Common; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Storage | ||
{ | ||
public abstract class BaseCassandraTypeMapping : RelationalTypeMapping | ||
{ | ||
public BaseCassandraTypeMapping( | ||
string storeType, | ||
Type clrType, | ||
DbType? dbType) | ||
: base(storeType, clrType, dbType) | ||
{ | ||
} | ||
|
||
protected BaseCassandraTypeMapping(RelationalTypeMappingParameters parameters) : base(parameters) { } | ||
|
||
public override DbParameter CreateParameter(DbCommand command, string name, object value, bool? nullable = null) | ||
{ | ||
var parameter = command.CreateParameter(); | ||
parameter.Direction = ParameterDirection.Input; | ||
parameter.ParameterName = name; | ||
value = ConvertUnderlyingEnumValueToEnum(value); | ||
if (Converter != null) | ||
{ | ||
value = Converter.ConvertToProvider(value); | ||
} | ||
|
||
parameter.Value = value ?? null; | ||
|
||
if (nullable.HasValue) | ||
{ | ||
parameter.IsNullable = nullable.Value; | ||
} | ||
|
||
if (DbType.HasValue) | ||
{ | ||
parameter.DbType = DbType.Value; | ||
} | ||
|
||
ConfigureParameter(parameter); | ||
|
||
return parameter; | ||
} | ||
|
||
private object? ConvertUnderlyingEnumValueToEnum(object? value) | ||
=> value?.GetType().IsInteger() == true && ClrType.UnwrapNullableType().IsEnum | ||
? Enum.ToObject(ClrType.UnwrapNullableType(), value) | ||
: value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) SimpleIdServer. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
namespace Microsoft.EntityFrameworkCore.Storage | ||
{ | ||
public class CassandraBoolTypeMapping: BaseCassandraTypeMapping | ||
{ | ||
public CassandraBoolTypeMapping(string storeType) | ||
: base(storeType, typeof(bool), System.Data.DbType.Boolean) | ||
{ | ||
} | ||
|
||
protected CassandraBoolTypeMapping(RelationalTypeMappingParameters parameters) : base(parameters) { } | ||
|
||
protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) | ||
=> new CassandraBoolTypeMapping(parameters); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/EFCore.Cassandra/Storage/CassandraDecimalTypeMapping.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) SimpleIdServer. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
namespace Microsoft.EntityFrameworkCore.Storage | ||
{ | ||
public class CassandraDecimalTypeMapping : BaseCassandraTypeMapping | ||
{ | ||
private const string DecimalFormatConst = "{0:0.0###########################}"; | ||
|
||
public CassandraDecimalTypeMapping(string storeType) | ||
: base(storeType, typeof(decimal), System.Data.DbType.Decimal) | ||
{ | ||
} | ||
|
||
protected CassandraDecimalTypeMapping(RelationalTypeMappingParameters parameters) : base(parameters) { } | ||
|
||
protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) | ||
=> new CassandraDecimalTypeMapping(parameters); | ||
|
||
protected override string SqlLiteralFormatString | ||
=> DecimalFormatConst; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/EFCore.Cassandra/Storage/CassandraDoubleTypeMapping.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) SimpleIdServer. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
namespace Microsoft.EntityFrameworkCore.Storage | ||
{ | ||
public class CassandraDoubleTypeMapping : BaseCassandraTypeMapping | ||
{ | ||
public CassandraDoubleTypeMapping(string storeType) | ||
: base(storeType, typeof(double), System.Data.DbType.Double) | ||
{ | ||
} | ||
|
||
protected CassandraDoubleTypeMapping(RelationalTypeMappingParameters parameters) : base(parameters) { } | ||
|
||
protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) | ||
=> new CassandraDoubleTypeMapping(parameters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) SimpleIdServer. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
using System; | ||
using System.Globalization; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Storage | ||
{ | ||
public class CassandraFloatTypeMapping : BaseCassandraTypeMapping | ||
{ | ||
public CassandraFloatTypeMapping(string storeType) | ||
: base(storeType, typeof(float), System.Data.DbType.Single) | ||
{ | ||
} | ||
|
||
protected CassandraFloatTypeMapping(RelationalTypeMappingParameters parameters) : base(parameters) { } | ||
|
||
protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) | ||
=> new CassandraFloatTypeMapping(parameters); | ||
|
||
protected override string GenerateNonNullSqlLiteral(object value) | ||
=> Convert.ToSingle(value).ToString("R", CultureInfo.InvariantCulture); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) SimpleIdServer. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
namespace Microsoft.EntityFrameworkCore.Storage | ||
{ | ||
public class CassandraIntTypeMapping: BaseCassandraTypeMapping | ||
{ | ||
public CassandraIntTypeMapping(string storeType) | ||
: base(storeType, typeof(int), System.Data.DbType.Int32) | ||
{ | ||
} | ||
|
||
protected CassandraIntTypeMapping(RelationalTypeMappingParameters parameters) : base(parameters) { } | ||
|
||
protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) | ||
=> new CassandraIntTypeMapping(parameters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) SimpleIdServer. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
namespace Microsoft.EntityFrameworkCore.Storage | ||
{ | ||
public class CassandraLongTypeMapping: BaseCassandraTypeMapping | ||
{ | ||
public CassandraLongTypeMapping(string storeType) | ||
: base(storeType, typeof(long), System.Data.DbType.Int64) | ||
{ | ||
} | ||
|
||
protected CassandraLongTypeMapping(RelationalTypeMappingParameters parameters) : base(parameters) { } | ||
|
||
protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) | ||
=> new CassandraLongTypeMapping(parameters); | ||
} | ||
} |
Oops, something went wrong.