Skip to content

Commit

Permalink
[fix] 修正特殊字段名的支持问题。fix #24
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Mar 14, 2024
1 parent 58357cc commit 50d8199
Show file tree
Hide file tree
Showing 8 changed files with 646 additions and 9 deletions.
4 changes: 2 additions & 2 deletions XCode/DataAccessLayer/DAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,10 @@ public static IList<IDataTable> Import(String xml)
/// <returns></returns>
public static IList<IDataTable> ImportFrom(String xmlFile)
{
if (xmlFile.IsNullOrEmpty()) return new IDataTable[0];
if (xmlFile.IsNullOrEmpty()) return [];

xmlFile = xmlFile.GetFullPath();
if (!File.Exists(xmlFile)) return new IDataTable[0];
if (!File.Exists(xmlFile)) return [];

return ModelHelper.FromXml(File.ReadAllText(xmlFile), CreateTable);
}
Expand Down
2 changes: 1 addition & 1 deletion XCode/DataAccessLayer/Model/IModelResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public virtual IDataColumn Fix(IDataColumn column)
if (column.Table == null || !column.Table.Columns.Any(e => e.Name.EqualIgnoreCase(name)))
column.Name = name;
else
column.Name = column.Name;
column.Name = column.ColumnName;
}

return column;
Expand Down
11 changes: 7 additions & 4 deletions XCode/DataAccessLayer/Model/ModelHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static class ModelHelper
/// <returns></returns>
public static IDataColumn[] GetColumns(this IDataTable table, String[] names)
{
if (names == null || names.Length <= 0) return new IDataColumn[0];
if (names == null || names.Length <= 0) return [];

//return table.Columns.Where(c => names.Any(n => c.Is(n))).ToArray();
var dcs = new List<IDataColumn>();
Expand Down Expand Up @@ -148,6 +148,9 @@ public static List<IDataColumn> GetAllColumns(this IDataTable table, IEnumerable
public static String CamelName(this IDataColumn column)
{
var name = column.Name;
if (name.IsNullOrEmpty()) name = column.ColumnName;
if (name.IsNullOrEmpty()) return name;

if (name.EqualIgnoreCase("id")) return "id";

// 全小写,直接返回
Expand Down Expand Up @@ -258,7 +261,7 @@ public static String ToXml(IEnumerable<IDataTable> tables, Object? option = null
/// <returns></returns>
public static IList<IDataTable> FromXml(String xml, Func<IDataTable> createTable, Object? option = null, IDictionary<String, String>? atts = null)
{
if (xml.IsNullOrEmpty()) return new IDataTable[0];
if (xml.IsNullOrEmpty()) return [];
if (createTable == null) throw new ArgumentNullException(nameof(createTable));

var settings = new XmlReaderSettings
Expand Down Expand Up @@ -342,7 +345,7 @@ public static IList<IDataTable> FromXml(String xml, Func<IDataTable> createTable
static void ReadTable(XmlReader reader, Func<IDataTable> createTable, IList<IDataTable> list)
{
var table = createTable();
(table as IXmlSerializable).ReadXml(reader);
(table as IXmlSerializable)!.ReadXml(reader);

// 判断是否存在属性NeedHistory设置且为true
var needHistory = table.Properties.FirstOrDefault(x => x.Key.EqualIgnoreCase("NeedHistory"));
Expand Down Expand Up @@ -592,7 +595,7 @@ public static void ReadXmlAttribute(XmlReader reader, Object value)
if (dc.Table == null || !dc.Table.Columns.Any(e => e.Name.EqualIgnoreCase(name)))
dc.Name = name;
else
dc.Name = dc.Name;
dc.Name = dc.ColumnName;
}
}
//reader.Skip();
Expand Down
2 changes: 1 addition & 1 deletion XUnitTest.XCode/Model/City.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Column Name="CreditNo" DataType="String" RawType="char(50)" Description="身份证号" />
<Column Name="Mobile" DataType="String" RawType="char(50)" Description="联系电话" />
<Column Name="BuildID" DataType="Int32" RawType="int(11)" Nullable="True" Description="楼宇ID" />
<Column ColumnName="Build_ID" DataType="Int32" RawType="int(11)" Nullable="True" Description="平台楼号" />
<Column Name="Build_ID" DataType="Int32" RawType="int(11)" Nullable="True" Description="平台楼号" />
<Column Name="UnitNum" DataType="String" RawType="varchar(20)" Length="20" Description="单元号" />
<Column Name="HouseNum" DataType="String" RawType="varchar(20)" Length="20" Description="房屋号" />
<Column Name="CreateUser" DataType="String" RawType="varchar(100)" Length="100" Description="创建者" />
Expand Down
Loading

0 comments on commit 50d8199

Please sign in to comment.