@@ -1,7 +1,6 @@
|
||||
|
||||
using Fluid;
|
||||
using IRaCIS.Core.Infra.EFCore;
|
||||
using IRaCIS.Core.Test.Template;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
@@ -48,6 +47,7 @@ partial class Program
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region 直接通过上下文拿到实体信息
|
||||
|
||||
|
||||
@@ -68,11 +68,11 @@ partial class Program
|
||||
string dataType = property.ClrType.Name;
|
||||
bool isNullable = property.IsNullable;
|
||||
|
||||
Console.WriteLine($" Column: {columnName}, Data Type: {dataType}, Is Nullable: {isNullable}");
|
||||
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
// 要生成的表名数组
|
||||
var tableNames = new List<string> { "Product"/*, "Order"*/ };
|
||||
@@ -154,4 +154,39 @@ partial class Program
|
||||
|
||||
public DateTime DateTimeNow = DateTime.Now;
|
||||
}
|
||||
|
||||
|
||||
#region 核对code first 暂时屏蔽
|
||||
|
||||
public void CheckCodeFirst()
|
||||
{
|
||||
var contextOptions = new DbContextOptionsBuilder<IRaCISDBContext>().UseSqlServer(@"Server=106.14.89.110,1435;Database=Test_IRC;User ID=sa;Password=xc@123456;TrustServerCertificate=true").Options;
|
||||
|
||||
using var dbContext = new IRaCISDBContext(contextOptions);
|
||||
|
||||
var dbModel = dbContext.Model;
|
||||
|
||||
foreach (var entityType in dbModel.GetEntityTypes())
|
||||
{
|
||||
string tableName = entityType.GetTableName();
|
||||
Console.WriteLine($"Table: {tableName}");
|
||||
|
||||
foreach (var property in entityType.GetProperties())
|
||||
{
|
||||
string columnName = property.GetColumnName();
|
||||
string dataType = property.ClrType.Name;
|
||||
bool isNullable = property.IsNullable;
|
||||
int? maxLength = property.GetMaxLength(); // 获取最大长度
|
||||
string columnType = property.GetColumnType(); // 获取数据库中的列类型
|
||||
bool isKey = property.IsKey(); // 判断是否为主键
|
||||
bool isIndex = property.IsIndex(); // 判断是否是索引
|
||||
object defaultValue = property.GetDefaultValue(); // 获取默认值
|
||||
bool isGenerated = property.ValueGenerated != Microsoft.EntityFrameworkCore.Metadata.ValueGenerated.Never; // 判断是否是自动生成的值
|
||||
|
||||
Console.WriteLine($" Column: {columnName}, Data Type: {dataType}, Is Nullable: {isNullable}, Max Length: {maxLength}, Column Type: {columnType}, Is Key: {isKey}, Is Index: {isIndex}, Default Value: {defaultValue}, Is Generated: {isGenerated}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user