+21
-15
@@ -47,25 +47,31 @@ partial class Program
|
||||
}
|
||||
#endregion
|
||||
|
||||
using (var context = new YourDbContext())
|
||||
|
||||
#region 直接通过上下文拿到实体信息
|
||||
|
||||
|
||||
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())
|
||||
{
|
||||
var model = context.Model;
|
||||
string tableName = entityType.GetTableName();
|
||||
Console.WriteLine($"Table: {tableName}");
|
||||
|
||||
foreach (var entityType in model.GetEntityTypes())
|
||||
foreach (var property in entityType.GetProperties())
|
||||
{
|
||||
string tableName = entityType.GetTableName();
|
||||
Console.WriteLine($"Table: {tableName}");
|
||||
string columnName = property.GetColumnName();
|
||||
string dataType = property.ClrType.Name;
|
||||
bool isNullable = property.IsNullable;
|
||||
|
||||
foreach (var property in entityType.GetProperties())
|
||||
{
|
||||
string columnName = property.GetColumnName();
|
||||
string dataType = property.ClrType.Name;
|
||||
bool isNullable = property.IsNullable;
|
||||
|
||||
Console.WriteLine($" Column: {columnName}, Data Type: {dataType}, Is Nullable: {isNullable}");
|
||||
}
|
||||
Console.WriteLine($" Column: {columnName}, Data Type: {dataType}, Is Nullable: {isNullable}");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
// 要生成的表名数组
|
||||
@@ -77,7 +83,7 @@ partial class Program
|
||||
foreach (var templateFilePath in Directory.GetFiles(templateFolderPath))
|
||||
{
|
||||
|
||||
var fileName=Path.GetFileNameWithoutExtension(templateFilePath);
|
||||
var fileName = Path.GetFileNameWithoutExtension(templateFilePath);
|
||||
|
||||
//模板放入具体的文件夹
|
||||
//var folder = fileName == "Entity" ? "Entity" : fileName.Replace("Entity", "");
|
||||
@@ -142,7 +148,7 @@ partial class Program
|
||||
//删除主键属性名
|
||||
public string LowercaseTableNameId => char.ToLower(TableName[0]) + TableName.Substring(1) + "Id";
|
||||
|
||||
public string LowercaseRepositoryName => $"_{char.ToLower(TableName[0]) + TableName.Substring(1)}Repository" ;
|
||||
public string LowercaseRepositoryName => $"_{char.ToLower(TableName[0]) + TableName.Substring(1)}Repository";
|
||||
|
||||
public string LowercaseQueryableName => $"{char.ToLower(TableName[0]) + TableName.Substring(1)}Queryable";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user