Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(efcore6): add support for efcore v6
- Loading branch information
Showing
13 changed files
with
734 additions
and
2 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
27 changes: 27 additions & 0 deletions
27
...c/entityframeworkcore6.validation/Aranasoft.Cobweb.EntityFrameworkCore6.Validation.csproj
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,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="..\..\..\..\netfx.props" /> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net6.0</TargetFrameworks> | ||
<AssemblyName>Aranasoft.Cobweb.EntityFrameworkCore.Validation</AssemblyName> | ||
<RootNamespace>Aranasoft.Cobweb.EntityFrameworkCore.Validation</RootNamespace> | ||
<VersionPrefix>1.60.0</VersionPrefix> | ||
<Platforms>AnyCPU;x64</Platforms> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<Description>Schema validation and testing components for Entity Framework Core.</Description> | ||
<PackageTags>entityframeworkcore;efcore;validation;$(PackageTags)</PackageTags> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="..\entityframeworkcore2.validation\SchemaValidationException.cs" Link="SchemaValidationException.cs" /> | ||
<Compile Include="..\entityframeworkcore3.validation\SchemaValidationOptions.cs" Link="SchemaValidationOptions.cs" /> | ||
<Compile Include="..\entityframeworkcore2.validation\SchemaValidatorExtensions.cs" Link="SchemaValidatorExtensions.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="[6,7)" /> | ||
</ItemGroup> | ||
|
||
</Project> |
176 changes: 176 additions & 0 deletions
176
src/entityframeworkcore/src/entityframeworkcore6.validation/SchemaComparison.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,176 @@ | ||
using System.Linq; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata; | ||
|
||
namespace Aranasoft.Cobweb.EntityFrameworkCore.Validation { | ||
internal static class SchemaComparison { | ||
public static bool TableExists(this DatabaseModel model, IEntityType type) { | ||
return TableExists(model, type.GetSchema() ?? model.DefaultSchema, type.GetTableName()); | ||
} | ||
|
||
public static bool ViewExists(this DatabaseModel model, string schema, string viewName) { | ||
var checkedSchema = schema ?? model.DefaultSchema; | ||
return model.Tables.Any(table => table.Schema == checkedSchema && table.Name == viewName); | ||
} | ||
|
||
public static DatabaseTable GetView(this DatabaseModel model, IEntityType type) { | ||
return GetTable(model, type.GetViewSchema() ?? model.DefaultSchema, type.GetViewName()); | ||
} | ||
|
||
public static DatabaseTable GetView(DatabaseModel model, string schema, string viewName) { | ||
var checkedSchema = schema ?? model.DefaultSchema; | ||
return model.Tables.FirstOrDefault(table => table.Schema == checkedSchema && table.Name == viewName); | ||
} | ||
|
||
public static bool ViewColumnExists(this DatabaseModel model, IProperty property) { | ||
return ViewColumnExists(model, property.DeclaringEntityType, property); | ||
} | ||
|
||
public static bool ViewColumnExists(this DatabaseModel model, | ||
IEntityType type, | ||
IProperty property) { | ||
return ViewColumnExists(model, | ||
type.GetViewSchema(), | ||
type.GetViewName(), | ||
property.GetColumnName(StoreObjectIdentifier.View(type.GetViewName(), type.GetSchema()))); | ||
} | ||
|
||
public static bool ViewColumnExists(this DatabaseModel model, | ||
string schema, | ||
string viewName, | ||
string columnName) { | ||
var viewModel = GetView(model, schema, viewName); | ||
return viewModel != null && viewModel.Columns.Any(column => column.Name == columnName); | ||
} | ||
|
||
public static DatabaseColumn GetViewColumn(this DatabaseModel model, IProperty property) { | ||
return GetViewColumn(model, property.DeclaringEntityType, property); | ||
} | ||
|
||
public static DatabaseColumn GetViewColumn(this DatabaseModel model, IEntityType type, IProperty property) { | ||
return GetViewColumn(model, | ||
type.GetViewSchema(), | ||
type.GetViewName(), | ||
property.GetColumnName(StoreObjectIdentifier.View(type.GetViewName(), type.GetSchema()))); | ||
} | ||
|
||
public static DatabaseColumn GetViewColumn(this DatabaseModel model, | ||
string schema, | ||
string viewName, | ||
string columnName) { | ||
var viewModel = GetView(model, schema, viewName); | ||
return viewModel?.Columns.FirstOrDefault(column => column.Name == columnName); | ||
} | ||
|
||
public static bool TableExists(this DatabaseModel model, string schema, string tableName) { | ||
var checkedSchema = schema ?? model.DefaultSchema; | ||
return model.Tables.Any(table => table.Schema == checkedSchema && table.Name == tableName); | ||
} | ||
|
||
public static DatabaseTable GetTable(this DatabaseModel model, IEntityType type) { | ||
return GetTable(model, type.GetSchema() ?? model.DefaultSchema, type.GetTableName()); | ||
} | ||
|
||
public static DatabaseTable GetTable(DatabaseModel model, string schema, string tableName) { | ||
var checkedSchema = schema ?? model.DefaultSchema; | ||
return model.Tables.FirstOrDefault(table => table.Schema == checkedSchema && table.Name == tableName); | ||
} | ||
|
||
public static bool TableColumnExists(this DatabaseModel model, IProperty property) { | ||
return TableColumnExists(model, property.DeclaringEntityType, property); | ||
} | ||
|
||
public static bool TableColumnExists(this DatabaseModel model, | ||
IEntityType type, | ||
IProperty property) { | ||
return TableColumnExists(model, | ||
type.GetSchema(), | ||
type.GetTableName(), | ||
property.GetColumnName(StoreObjectIdentifier.Table(type.GetTableName(), type.GetSchema()))); | ||
} | ||
|
||
public static bool TableColumnExists(this DatabaseModel model, | ||
string schema, | ||
string tableName, | ||
string columnName) { | ||
var tableModel = GetTable(model, schema, tableName); | ||
return tableModel != null && tableModel.Columns.Any(column => column.Name == columnName); | ||
} | ||
|
||
public static DatabaseColumn GetTableColumn(this DatabaseModel model, IProperty property) { | ||
return GetTableColumn(model, property.DeclaringEntityType, property); | ||
} | ||
|
||
public static DatabaseColumn GetTableColumn(this DatabaseModel model, IEntityType type, IProperty property) { | ||
return GetTableColumn(model, | ||
type.GetSchema(), | ||
type.GetTableName(), | ||
property.GetColumnName(StoreObjectIdentifier.Table(type.GetTableName(), type.GetSchema()))); | ||
} | ||
|
||
public static DatabaseColumn GetTableColumn(this DatabaseModel model, | ||
string schema, | ||
string tableName, | ||
string columnName) { | ||
var tableModel = GetTable(model, schema, tableName); | ||
return tableModel?.Columns.FirstOrDefault(column => column.Name == columnName); | ||
} | ||
|
||
public static bool IndexExists(this DatabaseModel model, IIndex index) { | ||
var entityType = index.DeclaringEntityType; | ||
return IndexExists(model, entityType.GetSchema(), entityType.GetTableName(), index.GetDatabaseName()); | ||
} | ||
|
||
public static bool IndexExists(this DatabaseModel model, string schema, string tableName, string indexName) { | ||
var tableModel = GetTable(model, schema, tableName); | ||
return tableModel != null && tableModel.Indexes.Any(column => column.Name == indexName); | ||
} | ||
|
||
public static DatabaseIndex GetIndex(this DatabaseModel model, IIndex index) { | ||
var entityType = index.DeclaringEntityType; | ||
return GetIndex(model, entityType.GetSchema(), entityType.GetTableName(), index.GetDatabaseName()); | ||
} | ||
|
||
public static DatabaseIndex GetIndex(this DatabaseModel model, | ||
string schema, | ||
string tableName, | ||
string indexName) { | ||
var tableModel = GetTable(model, schema, tableName); | ||
return tableModel?.Indexes.FirstOrDefault(index => index.Name == indexName); | ||
} | ||
|
||
public static bool ForeignKeyExists(this DatabaseModel model, | ||
IForeignKey foreignKey) { | ||
var entityType = foreignKey.DeclaringEntityType; | ||
return ForeignKeyExists(model, | ||
entityType.GetSchema(), | ||
entityType.GetTableName(), | ||
foreignKey.GetConstraintName()); | ||
} | ||
|
||
public static bool ForeignKeyExists(this DatabaseModel model, | ||
string schema, | ||
string tableName, | ||
string foreignKeyName) { | ||
var tableModel = GetTable(model, schema, tableName); | ||
return tableModel != null && tableModel.ForeignKeys.Any(column => column.Name == foreignKeyName); | ||
} | ||
|
||
public static DatabaseForeignKey GetForeignKey(this DatabaseModel model, IForeignKey foreignKey) { | ||
var entityType = foreignKey.DeclaringEntityType; | ||
return GetForeignKey(model, | ||
entityType.GetSchema(), | ||
entityType.GetTableName(), | ||
foreignKey.GetConstraintName()); | ||
} | ||
|
||
public static DatabaseForeignKey GetForeignKey(this DatabaseModel model, | ||
string schema, | ||
string tableName, | ||
string foreignKeyName) { | ||
var tableModel = GetTable(model, schema, tableName); | ||
return tableModel?.ForeignKeys.FirstOrDefault(index => index.Name == foreignKeyName); | ||
} | ||
} | ||
} |
Oops, something went wrong.