mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
update
This commit is contained in:
parent
5b20421fbb
commit
74a2cf5317
@ -1,67 +0,0 @@
|
|||||||
using FreeSql;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
public static class FreeSqlExtensionsEFCoreModelBuilderCodeFirstExtensions {
|
|
||||||
|
|
||||||
public static void ConfigEntity(this ICodeFirst codeFirst, IModel efmodel) {
|
|
||||||
|
|
||||||
foreach (var type in efmodel.GetEntityTypes()) {
|
|
||||||
|
|
||||||
codeFirst.ConfigEntity(type.ClrType, a => {
|
|
||||||
|
|
||||||
//表名
|
|
||||||
var relationalTableName = type.FindAnnotation("Relational:TableName");
|
|
||||||
if (relationalTableName != null) {
|
|
||||||
a.Name(relationalTableName.Value?.ToString() ?? type.ClrType.Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var prop in type.GetProperties()) {
|
|
||||||
|
|
||||||
var freeProp = a.Property(prop.Name);
|
|
||||||
|
|
||||||
//列名
|
|
||||||
var relationalColumnName = prop.FindAnnotation("Relational:ColumnName");
|
|
||||||
if (relationalColumnName != null) {
|
|
||||||
|
|
||||||
freeProp.Name(relationalColumnName.Value?.ToString() ?? prop.Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
//主键
|
|
||||||
freeProp.IsPrimary(prop.IsPrimaryKey());
|
|
||||||
|
|
||||||
//自增
|
|
||||||
freeProp.IsIdentity(
|
|
||||||
prop.ValueGenerated == ValueGenerated.Never ||
|
|
||||||
prop.ValueGenerated == ValueGenerated.OnAdd ||
|
|
||||||
prop.GetAnnotations().Where(z =>
|
|
||||||
z.Name == "SqlServer:ValueGenerationStrategy" && z.Value.ToString().Contains("IdentityColumn") //sqlserver 自增
|
|
||||||
|| z.Value.ToString().Contains("IdentityColumn") //其他数据库实现未经测试
|
|
||||||
).Any()
|
|
||||||
);
|
|
||||||
|
|
||||||
//可空
|
|
||||||
freeProp.IsNullable(prop.AfterSaveBehavior != PropertySaveBehavior.Throw);
|
|
||||||
|
|
||||||
//类型
|
|
||||||
var relationalColumnType = prop.FindAnnotation("Relational:ColumnType");
|
|
||||||
if (relationalColumnType != null) {
|
|
||||||
|
|
||||||
var dbType = relationalColumnType.ToString();
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(dbType)) {
|
|
||||||
|
|
||||||
var maxLength = prop.FindAnnotation("MaxLength");
|
|
||||||
if (maxLength != null)
|
|
||||||
dbType += $"({maxLength})";
|
|
||||||
|
|
||||||
freeProp.DbType(dbType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
|
||||||
<Version>0.0.12</Version>
|
|
||||||
<Authors>FreeSql</Authors>
|
|
||||||
<Product>FreeSql</Product>
|
|
||||||
<Description>FreeSql ICodeFirst 扩展库,实现从 EFCore FluentAPI/Attribute 读取,从而做到无缝接入已使用 EFCore 项目开发。</Description>
|
|
||||||
<PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl>
|
|
||||||
<RepositoryUrl>https://github.com/2881099/FreeSql</RepositoryUrl>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.8" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\FreeSql\FreeSql.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
14
FreeSql.sln
14
FreeSql.sln
@ -14,8 +14,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{C6A74E2A-6
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Tests.PerformanceTests", "FreeSql.Tests.PerformanceTests\FreeSql.Tests.PerformanceTests.csproj", "{446D9CBE-BFE4-4FB3-ADFD-4C1C5EA1B6EE}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Tests.PerformanceTests", "FreeSql.Tests.PerformanceTests\FreeSql.Tests.PerformanceTests.csproj", "{446D9CBE-BFE4-4FB3-ADFD-4C1C5EA1B6EE}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Extensions.EFCoreModelBuilder", "FreeSql.Extensions.EFCoreModelBuilder\FreeSql.Extensions.EFCoreModelBuilder.csproj", "{490CC8AF-C47C-4139-AED7-4FB6502F622B}"
|
|
||||||
EndProject
|
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{94C8A78D-AA15-47B2-A348-530CD86BFC1B}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{94C8A78D-AA15-47B2-A348-530CD86BFC1B}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "restful", "Examples\restful\restful.csproj", "{83D10565-AF9D-4EDC-8FB8-8C962A843F97}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "restful", "Examples\restful\restful.csproj", "{83D10565-AF9D-4EDC-8FB8-8C962A843F97}"
|
||||||
@ -72,18 +70,6 @@ Global
|
|||||||
{446D9CBE-BFE4-4FB3-ADFD-4C1C5EA1B6EE}.Release|x64.Build.0 = Release|Any CPU
|
{446D9CBE-BFE4-4FB3-ADFD-4C1C5EA1B6EE}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{446D9CBE-BFE4-4FB3-ADFD-4C1C5EA1B6EE}.Release|x86.ActiveCfg = Release|Any CPU
|
{446D9CBE-BFE4-4FB3-ADFD-4C1C5EA1B6EE}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{446D9CBE-BFE4-4FB3-ADFD-4C1C5EA1B6EE}.Release|x86.Build.0 = Release|Any CPU
|
{446D9CBE-BFE4-4FB3-ADFD-4C1C5EA1B6EE}.Release|x86.Build.0 = Release|Any CPU
|
||||||
{490CC8AF-C47C-4139-AED7-4FB6502F622B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{490CC8AF-C47C-4139-AED7-4FB6502F622B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{490CC8AF-C47C-4139-AED7-4FB6502F622B}.Debug|x64.ActiveCfg = Debug|Any CPU
|
|
||||||
{490CC8AF-C47C-4139-AED7-4FB6502F622B}.Debug|x64.Build.0 = Debug|Any CPU
|
|
||||||
{490CC8AF-C47C-4139-AED7-4FB6502F622B}.Debug|x86.ActiveCfg = Debug|Any CPU
|
|
||||||
{490CC8AF-C47C-4139-AED7-4FB6502F622B}.Debug|x86.Build.0 = Debug|Any CPU
|
|
||||||
{490CC8AF-C47C-4139-AED7-4FB6502F622B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{490CC8AF-C47C-4139-AED7-4FB6502F622B}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{490CC8AF-C47C-4139-AED7-4FB6502F622B}.Release|x64.ActiveCfg = Release|Any CPU
|
|
||||||
{490CC8AF-C47C-4139-AED7-4FB6502F622B}.Release|x64.Build.0 = Release|Any CPU
|
|
||||||
{490CC8AF-C47C-4139-AED7-4FB6502F622B}.Release|x86.ActiveCfg = Release|Any CPU
|
|
||||||
{490CC8AF-C47C-4139-AED7-4FB6502F622B}.Release|x86.Build.0 = Release|Any CPU
|
|
||||||
{83D10565-AF9D-4EDC-8FB8-8C962A843F97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{83D10565-AF9D-4EDC-8FB8-8C962A843F97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{83D10565-AF9D-4EDC-8FB8-8C962A843F97}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{83D10565-AF9D-4EDC-8FB8-8C962A843F97}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{83D10565-AF9D-4EDC-8FB8-8C962A843F97}.Debug|x64.ActiveCfg = Debug|Any CPU
|
{83D10565-AF9D-4EDC-8FB8-8C962A843F97}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
Loading…
x
Reference in New Issue
Block a user