-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
31 changed files
with
187 additions
and
25 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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
43 changes: 43 additions & 0 deletions
43
src/EFCore.SqlServer/Scaffolding/Internal/SqlServerScaffoldingHelper.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 |
---|---|---|
@@ -1,13 +1,56 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata; | ||
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata.Internal; | ||
using Microsoft.EntityFrameworkCore.Utilities; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal | ||
{ | ||
public class SqlServerScaffoldingHelper : IScaffoldingHelper | ||
{ | ||
private readonly ScaffoldingTypeMapper _scaffoldingTypeMapper; | ||
|
||
public SqlServerScaffoldingHelper([NotNull] ScaffoldingTypeMapper scaffoldingTypeMapper) | ||
{ | ||
Check.NotNull(scaffoldingTypeMapper, nameof(scaffoldingTypeMapper)); | ||
|
||
_scaffoldingTypeMapper = scaffoldingTypeMapper; | ||
} | ||
|
||
public virtual string GetProviderOptionsBuilder(string connectionString) | ||
{ | ||
return $"{nameof(SqlServerDbContextOptionsExtensions.UseSqlServer)}({CSharpUtilities.Instance.GenerateVerbatimStringLiteral(connectionString)});"; | ||
} | ||
|
||
public virtual TypeScaffoldingInfo GetTypeScaffoldingInfo(ColumnModel columnModel) | ||
{ | ||
if (columnModel.DataType == null) | ||
{ | ||
return null; | ||
} | ||
|
||
string underlyingDataType = null; | ||
columnModel.Table.Database.SqlServer().TypeAliases?.TryGetValue( | ||
SchemaQualifiedKey(columnModel.DataType, columnModel.SqlServer().DataTypeSchemaName), out underlyingDataType); | ||
|
||
var dataType = underlyingDataType ?? (columnModel.DataType + (columnModel.MaxLength.HasValue ? $"({columnModel.MaxLength.Value})" : "")); | ||
|
||
var typeScaffoldingInfo = _scaffoldingTypeMapper.FindMapping(dataType, keyOrIndex: false, rowVersion: false); | ||
|
||
if (underlyingDataType != null) | ||
{ | ||
return new TypeScaffoldingInfo( | ||
typeScaffoldingInfo.ClrType, | ||
inferred: false, | ||
scaffoldUnicode: typeScaffoldingInfo.ScaffoldUnicode, | ||
scaffoldMaxLength: typeScaffoldingInfo.ScaffoldMaxLength); | ||
} | ||
|
||
return typeScaffoldingInfo; | ||
} | ||
|
||
private static string SchemaQualifiedKey(string name, string schema = null) => "[" + (schema ?? "") + "].[" + name + "]"; | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
36 changes: 36 additions & 0 deletions
36
src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteScaffoldingHelper.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 |
---|---|---|
@@ -1,13 +1,49 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata; | ||
using Microsoft.EntityFrameworkCore.Utilities; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal | ||
{ | ||
public class SqliteScaffoldingHelper : IScaffoldingHelper | ||
{ | ||
private readonly ScaffoldingTypeMapper _scaffoldingTypeMapper; | ||
|
||
public SqliteScaffoldingHelper([NotNull] ScaffoldingTypeMapper scaffoldingTypeMapper) | ||
{ | ||
Check.NotNull(scaffoldingTypeMapper, nameof(scaffoldingTypeMapper)); | ||
|
||
_scaffoldingTypeMapper = scaffoldingTypeMapper; | ||
} | ||
|
||
public virtual string GetProviderOptionsBuilder(string connectionString) | ||
{ | ||
return $"{nameof(SqliteDbContextOptionsBuilderExtensions.UseSqlite)}({CSharpUtilities.Instance.GenerateVerbatimStringLiteral(connectionString)});"; | ||
} | ||
|
||
public virtual TypeScaffoldingInfo GetTypeScaffoldingInfo(ColumnModel columnModel) | ||
{ | ||
if (columnModel.DataType == null) | ||
{ | ||
return null; | ||
} | ||
|
||
var dataType = columnModel.DataType + (columnModel.MaxLength.HasValue ? $"({columnModel.MaxLength.Value})" : ""); | ||
|
||
var typeScaffoldingInfo = _scaffoldingTypeMapper.FindMapping(dataType, keyOrIndex: false, rowVersion: false); | ||
|
||
if (columnModel.DataType == "") | ||
{ | ||
return new TypeScaffoldingInfo( | ||
typeScaffoldingInfo.ClrType, | ||
inferred: true, | ||
scaffoldUnicode: typeScaffoldingInfo.ScaffoldUnicode, | ||
scaffoldMaxLength: typeScaffoldingInfo.ScaffoldMaxLength); | ||
} | ||
|
||
return typeScaffoldingInfo; | ||
} | ||
} | ||
} |
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