调整精度位数相关的代码生成

This commit is contained in:
大石头 2025-07-31 21:03:13 +08:00
parent 4913a26137
commit 00b88f316c
2 changed files with 6 additions and 4 deletions

View File

@ -720,7 +720,9 @@ public class EntityBuilder : ClassBuilder
if (!dc.ItemType.IsNullOrEmpty()) sb.AppendFormat(", ItemType = \"{0}\"", dc.ItemType);
// 支持生成带精度的特性
if (dc.Precision > 0 || dc.Scale > 0) sb.AppendFormat(", Precision = {0}, Scale = {1}", dc.Precision, dc.Scale);
var def = ModelHelper.FixDefaultByType(dc.Clone(dc.Table) as IDataColumn, dc);
if (dc.Precision > 0 && dc.Precision != def.Precision) sb.AppendFormat(", Precision = {0}", dc.Precision);
if (dc.Scale > 0 && dc.Scale != def.Scale) sb.AppendFormat(", Scale = {0}", dc.Scale);
// 默认值
if (!dc.DefaultValue.IsNullOrEmpty()) sb.AppendFormat(", DefaultValue = \"{0}\"", dc.DefaultValue);

View File

@ -775,7 +775,7 @@ public static class ModelHelper
/// <param name="dc"></param>
/// <param name="oridc"></param>
/// <returns></returns>
private static IDataColumn FixDefaultByType(this IDataColumn dc, IDataColumn? oridc)
public static IDataColumn FixDefaultByType(this IDataColumn dc, IDataColumn? oridc)
{
if (dc.DataType == null) return dc;
@ -829,8 +829,8 @@ public static class ModelHelper
case TypeCode.Decimal:
dc.RawType = "money";
dc.Nullable = false;
dc.Precision = 20;
dc.Scale = 4;
//dc.Precision = 20;
//dc.Scale = 4;
break;
case TypeCode.String:
// 原来就是普通字符串或者非ntext字符串一律转nvarchar