E.EntityFrameworkCore.Extensions 0.1.0

dotnet add package E.EntityFrameworkCore.Extensions --version 0.1.0                
NuGet\Install-Package E.EntityFrameworkCore.Extensions -Version 0.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="E.EntityFrameworkCore.Extensions" Version="0.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add E.EntityFrameworkCore.Extensions --version 0.1.0                
#r "nuget: E.EntityFrameworkCore.Extensions, 0.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install E.EntityFrameworkCore.Extensions as a Cake Addin
#addin nuget:?package=E.EntityFrameworkCore.Extensions&version=0.1.0

// Install E.EntityFrameworkCore.Extensions as a Cake Tool
#tool nuget:?package=E.EntityFrameworkCore.Extensions&version=0.1.0                

E.EntityFrameworkCore.Extensions


EntityFrameworkCore 的扩展库

NuGet Version

NuGet Downloads

功能


目前已经实现的功能

  • PostgreSql DbSet 表名、视图名、列名自动处理为小写
  • Oracle DbSet 表名、视图名、列名自动处理为大写
  • 自定义 DbSet 校验处理函数
  • 自定义 DbQuery 校验处理函数
  • 自定义 Column(Field) 校验处理函数
  • 自定义列名长度,自动进行裁剪
  • 自动跳过处理 DbContext 程序集中已实现的 IEntityTypeConfiguration
  • 增加是否使用 DbSet/DbQuery 名称作为 表名称/视图名称 选项
  • 增加字符串列设置默认数据长度 校验函数

基本用法

1. 引入nuget包

  • dotnet cli

dotnet add package E.EntityFrameworkCore.Extensions

  • nuget package manager

Install-Package E.EntityFrameworkCore.Extensions

2. 配置 DbContext

  • 重写 DbContext的 OnModelCreating 函数
  • 引入命名空间 using E;

3. 配置 E.EntityFrameworkCore.Extensions

以下代码均处于 OnModelCreating 函数中

PostgreSql

base.OnModelCreating(modelBuilder);
  
// 禁用 使用DbSet名称作为表名和视图名称,优先读Table标记,其次类名
E.EntityFrameworkCoreTableViewExtensions.UseDbSetNameToTableName = false;

// 设置小写
E.EntityFrameworkCoreTableViewExtensions.SetCaseType(modelBuilder, ColumnNameCaseType.Lower);

// 自定义要处理的字段类型,较多,此处不贴完整
E.EntityFrameworkCoreTableViewExtensions.DbMapTypes.Add("System.String[]");
E.EntityFrameworkCoreTableViewExtensions.DbMapTypes.Add("System.Boolean[]");
E.EntityFrameworkCoreTableViewExtensions.DbMapTypes.Add("System.Int32[]");

// 处理此数据库上下文类型中 DbSet
// 参数为 true,则 自动跳过处理 DbContext 程序集中已实现的 IEntityTypeConfiguration 的 DbSet<Entity>
modelBuilder.CaseAllDbSetNameAndColumnName<BloggingContext>(/* true */);

Oracle

base.OnModelCreating(modelBuilder);


// 禁用 使用DbSet名称作为表名和视图名称,优先读Table标记,其次类名
E.EntityFrameworkCoreTableViewExtensions.UseDbSetNameToTableName = false;

// 设置大写
E.EntityFrameworkCoreTableViewExtensions.SetCaseType(modelBuilder, ColumnNameCaseType.Upper);

// 使用列名长度限制,最大30
E.EntityFrameworkCoreTableViewExtensions.UseColumnNameMaxLength = true;
E.EntityFrameworkCoreTableViewExtensions.ColumnNameMaxLength = 30;

// 使用默认字符串长度
E.EntityFrameworkCoreTableViewExtensions.UseDefaultStringMaxLength = true;
E.EntityFrameworkCoreTableViewExtensions.DefaultStringMaxLength = 256;
// 自定义 字符串列数据长度 是否设置默认长度 校验函数
E.EntityFrameworkCoreTableViewExtensions.CheckUseDefaultStringMaxLength = (type, prop) =>
{

    var checkResult = new CheckUseDefaultStringMaxLenghtResult();

    // 如果实体的命名空间为 TestWebApp.Database.Models 则设置长度为200
    if (type.Namespace.StartsWith("TestWebApp.Database.Models"))
    {
        checkResult.Success = true;
        checkResult.MaxLength = 200;
    }


    return checkResult;
};

// 处理此数据库上下文类型中 DbSet
// 参数为 true,则 自动跳过处理 DbContext 程序集中已实现的 IEntityTypeConfiguration 的 DbSet<Entity>
modelBuilder.CaseAllDbSetNameAndColumnName<BloggingContext>(/* true */);

自定义校验处理函数

以下代码均处于 OnModelCreating 函数中

  // DbSet Check
  E.EntityFrameworkCoreTableViewExtensions.DbSetCheck = (info) =>
  {
      // 你的校验逻辑
      return true;// or false
  };
  
  // Column Chcek
  E.EntityFrameworkCoreTableViewExtensions.ColumnCheck = (info) =>
  {
      // 你的校验逻辑
      return true;// or false
  };

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.0 1,689 7/7/2020
0.0.8 3,970 5/16/2019
0.0.7 539 5/16/2019
0.0.5 1,383 5/8/2019
0.0.4 554 5/7/2019
0.0.3 555 5/7/2019
0.0.2 545 5/7/2019
0.0.1 549 5/7/2019