[fix] 代码生成时,如果命名格式不是默认,则要做区分大小写比较,例如字段名fullName,属性名用FullName,命名格式用下划线,如果不区分大小写比较,则会隐藏掉字段名ColumnName,下一次生成又会生成 full_name 的字段名。
This commit is contained in:
parent
a5983f5a7a
commit
f2a1032941
|
@ -6,9 +6,9 @@ using System.Runtime.Serialization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using NewLife;
|
|
||||||
using NewLife.Log;
|
using NewLife.Log;
|
||||||
using NewLife.Reflection;
|
using NewLife.Reflection;
|
||||||
|
using XCode.Code;
|
||||||
|
|
||||||
namespace XCode.DataAccessLayer;
|
namespace XCode.DataAccessLayer;
|
||||||
|
|
||||||
|
@ -231,14 +231,15 @@ public static class ModelHelper
|
||||||
writer.WriteEndElement();
|
writer.WriteEndElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var nameFormat = option is EntityBuilderOption opt ? opt.NameFormat : NameFormats.Default;
|
||||||
{
|
{
|
||||||
writer.WriteStartElement("Tables");
|
writer.WriteStartElement("Tables");
|
||||||
|
|
||||||
// 回写xml模型,排除IsHistory=true的表单,仅仅保留原始表单
|
// 回写xml模型,排除IsHistory=true的表单,仅仅保留原始表单
|
||||||
foreach (var item in tables.Where(x => x is not XTable xt || !xt.IsHistory))
|
foreach (var table in tables.Where(x => x is not XTable xt || !xt.IsHistory))
|
||||||
{
|
{
|
||||||
writer.WriteStartElement("Table");
|
writer.WriteStartElement("Table");
|
||||||
(item as IXmlSerializable)!.WriteXml(writer);
|
table.WriteXml(writer, nameFormat);
|
||||||
writer.WriteEndElement();
|
writer.WriteEndElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,9 +313,9 @@ public static class ModelHelper
|
||||||
{
|
{
|
||||||
if (option != null)
|
if (option != null)
|
||||||
{
|
{
|
||||||
if (option is IXmlSerializable xml2)
|
//if (option is IXmlSerializable xml2)
|
||||||
xml2.ReadXml(reader);
|
// xml2.ReadXml(reader);
|
||||||
else
|
//else
|
||||||
ReadXml(reader, option);
|
ReadXml(reader, option);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -345,7 +346,7 @@ public static class ModelHelper
|
||||||
static void ReadTable(XmlReader reader, Func<IDataTable> createTable, IList<IDataTable> list)
|
static void ReadTable(XmlReader reader, Func<IDataTable> createTable, IList<IDataTable> list)
|
||||||
{
|
{
|
||||||
var table = createTable();
|
var table = createTable();
|
||||||
(table as IXmlSerializable)!.ReadXml(reader);
|
table.ReadXml(reader);
|
||||||
|
|
||||||
// 判断是否存在属性NeedHistory设置且为true
|
// 判断是否存在属性NeedHistory设置且为true
|
||||||
var needHistory = table.Properties.FirstOrDefault(x => x.Key.EqualIgnoreCase("NeedHistory"));
|
var needHistory = table.Properties.FirstOrDefault(x => x.Key.EqualIgnoreCase("NeedHistory"));
|
||||||
|
@ -433,7 +434,9 @@ public static class ModelHelper
|
||||||
// 清空默认的原始类型,让其从xml读取
|
// 清空默认的原始类型,让其从xml读取
|
||||||
dc.RawType = null;
|
dc.RawType = null;
|
||||||
}
|
}
|
||||||
(dc as IXmlSerializable)!.ReadXml(reader);
|
ReadXmlAttribute(reader, dc);
|
||||||
|
// 跳过当前节点
|
||||||
|
reader.Skip();
|
||||||
|
|
||||||
// 未指定DataType,但指定了Type,修正为枚举整型
|
// 未指定DataType,但指定了Type,修正为枚举整型
|
||||||
if (dc.DataType == null && dc.Properties.ContainsKey("Type")) dc.DataType = typeof(Int32);
|
if (dc.DataType == null && dc.Properties.ContainsKey("Type")) dc.DataType = typeof(Int32);
|
||||||
|
@ -454,7 +457,10 @@ public static class ModelHelper
|
||||||
while (reader.IsStartElement())
|
while (reader.IsStartElement())
|
||||||
{
|
{
|
||||||
var di = table.CreateIndex();
|
var di = table.CreateIndex();
|
||||||
(di as IXmlSerializable)!.ReadXml(reader);
|
ReadXmlAttribute(reader, di);
|
||||||
|
// 跳过当前节点
|
||||||
|
reader.Skip();
|
||||||
|
|
||||||
di.Fix();
|
di.Fix();
|
||||||
table.Indexes.Add(di);
|
table.Indexes.Add(di);
|
||||||
}
|
}
|
||||||
|
@ -483,18 +489,21 @@ public static class ModelHelper
|
||||||
/// <summary>写入</summary>
|
/// <summary>写入</summary>
|
||||||
/// <param name="table"></param>
|
/// <param name="table"></param>
|
||||||
/// <param name="writer"></param>
|
/// <param name="writer"></param>
|
||||||
public static IDataTable WriteXml(this IDataTable table, XmlWriter writer)
|
/// <param name="nameFormat"></param>
|
||||||
|
public static IDataTable WriteXml(this IDataTable table, XmlWriter writer, NameFormats nameFormat = NameFormats.Default)
|
||||||
{
|
{
|
||||||
WriteXml(writer, table);
|
var ignoreNameCase = nameFormat <= NameFormats.Default;
|
||||||
|
|
||||||
|
WriteXml(writer, table, false, ignoreNameCase);
|
||||||
|
|
||||||
// 写字段
|
// 写字段
|
||||||
if (table.Columns.Count > 0)
|
if (table.Columns.Count > 0)
|
||||||
{
|
{
|
||||||
writer.WriteStartElement("Columns");
|
writer.WriteStartElement("Columns");
|
||||||
foreach (IXmlSerializable item in table.Columns)
|
foreach (var dc in table.Columns)
|
||||||
{
|
{
|
||||||
writer.WriteStartElement("Column");
|
writer.WriteStartElement("Column");
|
||||||
item.WriteXml(writer);
|
WriteXml(writer, dc, false, ignoreNameCase);
|
||||||
writer.WriteEndElement();
|
writer.WriteEndElement();
|
||||||
}
|
}
|
||||||
writer.WriteEndElement();
|
writer.WriteEndElement();
|
||||||
|
@ -502,10 +511,10 @@ public static class ModelHelper
|
||||||
if (table.Indexes.Count > 0)
|
if (table.Indexes.Count > 0)
|
||||||
{
|
{
|
||||||
writer.WriteStartElement("Indexes");
|
writer.WriteStartElement("Indexes");
|
||||||
foreach (IXmlSerializable item in table.Indexes)
|
foreach (var di in table.Indexes)
|
||||||
{
|
{
|
||||||
writer.WriteStartElement("Index");
|
writer.WriteStartElement("Index");
|
||||||
item.WriteXml(writer);
|
WriteXml(writer, di, false, true);
|
||||||
writer.WriteEndElement();
|
writer.WriteEndElement();
|
||||||
}
|
}
|
||||||
writer.WriteEndElement();
|
writer.WriteEndElement();
|
||||||
|
@ -634,7 +643,8 @@ public static class ModelHelper
|
||||||
/// <param name="writer"></param>
|
/// <param name="writer"></param>
|
||||||
/// <param name="value">数值</param>
|
/// <param name="value">数值</param>
|
||||||
/// <param name="writeDefaultValueMember">是否写数值为默认值的成员。为了节省空间,默认不写。</param>
|
/// <param name="writeDefaultValueMember">是否写数值为默认值的成员。为了节省空间,默认不写。</param>
|
||||||
public static void WriteXml(XmlWriter writer, Object value, Boolean writeDefaultValueMember = false)
|
/// <param name="ignoreNameCase">忽略名称大小写</param>
|
||||||
|
public static void WriteXml(XmlWriter writer, Object value, Boolean writeDefaultValueMember = false, Boolean ignoreNameCase = true)
|
||||||
{
|
{
|
||||||
var type = value.GetType();
|
var type = value.GetType();
|
||||||
var def = GetDefault(type);
|
var def = GetDefault(type);
|
||||||
|
@ -681,16 +691,24 @@ public static class ModelHelper
|
||||||
if (code == TypeCode.String && "" + obj == "" + dobj) continue;
|
if (code == TypeCode.String && "" + obj == "" + dobj) continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code == TypeCode.String)
|
if (code == TypeCode.String && obj is String str)
|
||||||
{
|
{
|
||||||
// 如果别名与名称相同,则跳过,不区分大小写
|
// 如果别名与名称相同,则跳过,不区分大小写
|
||||||
// 改为区分大小写,避免linux环境下 mysql 数据库存在
|
// 改为区分大小写,避免linux环境下 mysql 数据库存在
|
||||||
if (pi.Name == "Name")
|
if (pi.Name == "Name")
|
||||||
name = (String)obj;
|
name = str;
|
||||||
else if (pi.Name is "TableName" or "ColumnName")
|
else if (pi.Name is "TableName" or "ColumnName")
|
||||||
{
|
{
|
||||||
if (name == (String)obj) continue;
|
if (name == str) continue;
|
||||||
if (/*ignoreNameCase &&*/ name.EqualIgnoreCase((String)obj)) continue;
|
if (ignoreNameCase)
|
||||||
|
{
|
||||||
|
if (name.EqualIgnoreCase(str)) continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 如果全小写或者全大写,也不缺分大小写比较
|
||||||
|
if ((str == str.ToLower() || str == str.ToUpper()) && name.EqualIgnoreCase(str)) continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (code == TypeCode.Object)
|
else if (code == TypeCode.Object)
|
||||||
|
@ -723,9 +741,8 @@ public static class ModelHelper
|
||||||
if (obj != null) writer.WriteAttributeString(pi.Name, obj + "");
|
if (obj != null) writer.WriteAttributeString(pi.Name, obj + "");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value is IDataTable)
|
if (value is IDataTable table)
|
||||||
{
|
{
|
||||||
var table = value as IDataTable;
|
|
||||||
// 写入扩展属性作为特性
|
// 写入扩展属性作为特性
|
||||||
if (table.Properties.Count > 0)
|
if (table.Properties.Count > 0)
|
||||||
{
|
{
|
||||||
|
@ -735,9 +752,8 @@ public static class ModelHelper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (value is IDataColumn)
|
else if (value is IDataColumn column)
|
||||||
{
|
{
|
||||||
var column = value as IDataColumn;
|
|
||||||
// 写入扩展属性作为特性
|
// 写入扩展属性作为特性
|
||||||
if (column.Properties.Count > 0)
|
if (column.Properties.Count > 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using NewLife;
|
|
||||||
using NewLife.Collections;
|
using NewLife.Collections;
|
||||||
|
|
||||||
namespace XCode.DataAccessLayer;
|
namespace XCode.DataAccessLayer;
|
||||||
|
@ -12,7 +11,7 @@ namespace XCode.DataAccessLayer;
|
||||||
[DisplayName("字段模型")]
|
[DisplayName("字段模型")]
|
||||||
[Description("字段模型")]
|
[Description("字段模型")]
|
||||||
[XmlRoot("Column")]
|
[XmlRoot("Column")]
|
||||||
class XField : SerializableDataMember, IDataColumn, ICloneable
|
class XField : /*SerializableDataMember,*/ IDataColumn, ICloneable
|
||||||
{
|
{
|
||||||
#region 属性
|
#region 属性
|
||||||
/// <summary>名称</summary>
|
/// <summary>名称</summary>
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
using System;
|
using System.ComponentModel;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using NewLife;
|
|
||||||
|
|
||||||
namespace XCode.DataAccessLayer;
|
namespace XCode.DataAccessLayer;
|
||||||
|
|
||||||
|
@ -11,7 +9,7 @@ namespace XCode.DataAccessLayer;
|
||||||
[DisplayName("索引模型")]
|
[DisplayName("索引模型")]
|
||||||
[Description("索引模型")]
|
[Description("索引模型")]
|
||||||
[XmlRoot("Index")]
|
[XmlRoot("Index")]
|
||||||
class XIndex : SerializableDataMember, IDataIndex, ICloneable
|
class XIndex : /*SerializableDataMember,*/ IDataIndex, ICloneable
|
||||||
{
|
{
|
||||||
#region 属性
|
#region 属性
|
||||||
/// <summary>名称</summary>
|
/// <summary>名称</summary>
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace XCode.DataAccessLayer;
|
||||||
[DisplayName("表模型")]
|
[DisplayName("表模型")]
|
||||||
[Description("表模型")]
|
[Description("表模型")]
|
||||||
[XmlRoot("Table")]
|
[XmlRoot("Table")]
|
||||||
class XTable : IDataTable, ICloneable, IXmlSerializable
|
class XTable : IDataTable, ICloneable//, IXmlSerializable
|
||||||
{
|
{
|
||||||
#region 基本属性
|
#region 基本属性
|
||||||
///// <summary>编号</summary>
|
///// <summary>编号</summary>
|
||||||
|
@ -243,16 +243,16 @@ class XTable : IDataTable, ICloneable, IXmlSerializable
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region IXmlSerializable 成员
|
#region IXmlSerializable 成员
|
||||||
/// <summary>获取架构</summary>
|
///// <summary>获取架构</summary>
|
||||||
/// <returns></returns>
|
///// <returns></returns>
|
||||||
XmlSchema IXmlSerializable.GetSchema() => null;
|
//XmlSchema IXmlSerializable.GetSchema() => null;
|
||||||
|
|
||||||
/// <summary>读取</summary>
|
///// <summary>读取</summary>
|
||||||
/// <param name="reader"></param>
|
///// <param name="reader"></param>
|
||||||
void IXmlSerializable.ReadXml(XmlReader reader) => ModelHelper.ReadXml(this, reader);
|
//void IXmlSerializable.ReadXml(XmlReader reader) => ModelHelper.ReadXml(this, reader);
|
||||||
|
|
||||||
/// <summary>写入</summary>
|
///// <summary>写入</summary>
|
||||||
/// <param name="writer"></param>
|
///// <param name="writer"></param>
|
||||||
void IXmlSerializable.WriteXml(XmlWriter writer) => ModelHelper.WriteXml(this, writer);
|
//void IXmlSerializable.WriteXml(XmlWriter writer) => ModelHelper.WriteXml(this, writer);
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
|
@ -81,6 +81,7 @@
|
||||||
<Compile Remove="DataAccessLayer\Common\ConnectionPool.cs" />
|
<Compile Remove="DataAccessLayer\Common\ConnectionPool.cs" />
|
||||||
<Compile Remove="DataAccessLayer\Database\Firebird.cs" />
|
<Compile Remove="DataAccessLayer\Database\Firebird.cs" />
|
||||||
<Compile Remove="DataAccessLayer\Database\Network.cs" />
|
<Compile Remove="DataAccessLayer\Database\Network.cs" />
|
||||||
|
<Compile Remove="DataAccessLayer\Model\SerializableDataMember.cs" />
|
||||||
<Compile Remove="DataAccessLayer\MSPageSplit.cs" />
|
<Compile Remove="DataAccessLayer\MSPageSplit.cs" />
|
||||||
<Compile Remove="Membership\IPasswordProvider.cs" />
|
<Compile Remove="Membership\IPasswordProvider.cs" />
|
||||||
<Compile Remove="Membership\MenuProvider.cs" />
|
<Compile Remove="Membership\MenuProvider.cs" />
|
||||||
|
|
Loading…
Reference in New Issue