Skip to content

Commit

Permalink
Revert "XCode支持数组字段,支持写入和读取"
Browse files Browse the repository at this point in the history
This reverts commit 818579c.
  • Loading branch information
nnhy committed Mar 28, 2021
1 parent a3cefcf commit f02283d
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 118 deletions.
14 changes: 0 additions & 14 deletions NewLife.Core/Reflection/IReflect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -668,20 +668,6 @@ public virtual Object ChangeType(Object value, Type conversionType)
if (code >= TypeCode.Int16 && code <= TypeCode.UInt64 && str.Length <= 10) return Convert.ChangeType(value.ToLong(), conversionType);
}

// 处理数组
if (conversionType == typeof(Int32[]))
{
return (value as String).SplitAsInt();
}
else if (conversionType == typeof(Int64[]))
{
return (value as String).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(e => e.ToLong()).ToArray();
}
else if (conversionType == typeof(String[]))
{
return (value as String).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
}

if (value != null)
{
// 尝试基础类型转换
Expand Down
20 changes: 0 additions & 20 deletions XCode/DataAccessLayer/Common/DbBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -795,26 +795,6 @@ public virtual String FormatValue(IDataColumn column, Object value)
else if (value != null)
type = value.GetType();

// 支持整型数组和字符串数组
if (type == typeof(Int32[]))
{
type = typeof(String);
if (value is Int32[] arr)
value = arr.Length == 0 ? "" : ("," + arr.Join(",") + ",");
}
else if (type == typeof(Int64[]))
{
type = typeof(String);
if (value is Int64[] arr)
value = arr.Length == 0 ? "" : ("," + arr.Join(",") + ",");
}
else if (type == typeof(String[]))
{
type = typeof(String);
if (value is String[] arr)
value = arr.Length == 0 ? "" : ("," + arr.Join(",") + ",");
}

// 如果类型是Nullable的,则获取对应的类型
type = Nullable.GetUnderlyingType(type) ?? type;

Expand Down
2 changes: 0 additions & 2 deletions XCode/DataAccessLayer/DAL_Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public IEnumerable<T> Query<T>(String sql, Object param = null)
if (utype != null) type = utype;
if (type.GetTypeCode() != TypeCode.Object) return dt.Rows.Select(e => e[0].ChangeType<T>());

if (type != typeof(Int32[]) || type != typeof(Int64[]) || type != typeof(String[])) return dt.Rows.Select(e => e[0].ChangeType<T>());

return dt.ReadModels<T>();
}

Expand Down
8 changes: 1 addition & 7 deletions XCode/DataAccessLayer/MetaData/DbMetaData_Positive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,7 @@ protected virtual String GetFieldType(IDataColumn field)
// 处理枚举
if (type.IsEnum) type = typeof(Int32);

if (!Types.TryGetValue(type, out var ns))
{
// 处理数组
if (type == typeof(Int32[]) || type == typeof(Int64[]) || type == typeof(String[])) type = typeof(String);

if (!Types.TryGetValue(type, out ns)) return null;
}
if (!Types.TryGetValue(type, out var ns)) return null;

var typeName = ns.FirstOrDefault();
// 大文本选第二个类型
Expand Down
18 changes: 0 additions & 18 deletions XCode/Entity/DataRowEntityAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using NewLife;
using NewLife.Data;
using XCode.Configuration;
Expand Down Expand Up @@ -228,23 +227,6 @@ private void SetValue(IEntity entity, String name, Type type, Object value)
value = new Guid(str);
}
}
// 处理数组
else if (type == typeof(Int32[]))
{
//type = typeof(String);
if (value is String str)
value = str.SplitAsInt();
}
else if (type == typeof(Int64[]))
{
if (value is String str)
value = str.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(e => e.ToLong()).ToArray();
}
else if (type == typeof(String[]))
{
if (value is String str)
value = str.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
}

//// 不影响脏数据的状态
//var ds = entity.Dirtys;
Expand Down
2 changes: 1 addition & 1 deletion XCode/Membership/Member.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Column Name="Code" DataType="String" Description="代码。身份证、员工编号等" />
<Column Name="Avatar" DataType="String" Length="200" Description="头像" />
<Column Name="RoleID" DataType="Int32" Description="角色。主要角色" />
<Column Name="RoleIds" DataType="Int32[]" Nullable="True" Description="角色组。次要角色集合" />
<Column Name="RoleIds" DataType="String" Length="200" Description="角色组。次要角色集合" />
<Column Name="DepartmentID" DataType="Int32" Description="部门。组织机构" />
<Column Name="Online" DataType="Boolean" Description="在线" />
<Column Name="Enable" DataType="Boolean" Description="启用" />
Expand Down
12 changes: 9 additions & 3 deletions XCode/Membership/用户.Biz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ public override void Valid(Boolean isNew)
if (ids.Length > 0)
{
RoleID = ids[0];
RoleIds = ids.Skip(1).ToArray();
var str = ids.Skip(1).Join();
if (!str.IsNullOrEmpty()) str = "," + str + ",";
RoleIds = str;
}
}

Expand All @@ -128,6 +130,10 @@ protected override Int32 OnDelete()
/// <summary>部门</summary>
[Map(__.DepartmentID, typeof(Department), __.ID)]
public String DepartmentName => Department?.ToString();

///// <summary>兼容旧版角色组</summary>
//[Obsolete("=>RoleIds")]
//public String RoleIDs { get => RoleIds; set => RoleIds = value; }
#endregion

#region 扩展查询
Expand Down Expand Up @@ -512,7 +518,7 @@ private Boolean DisableAdmin()
/// <returns></returns>
public virtual Int32[] GetRoleIDs()
{
var ids = RoleIds.Where(e => e > 0).OrderBy(e => e).ToList();
var ids = RoleIds.SplitAsInt().OrderBy(e => e).ToList();
if (RoleID > 0) ids.Insert(0, RoleID);

return ids.Distinct().ToArray();
Expand Down Expand Up @@ -613,7 +619,7 @@ public partial interface IUser
Int32 RoleID { get; set; }

/// <summary>角色组。次要角色集合</summary>
Int32[] RoleIds { get; set; }
String RoleIds { get; set; }

/// <summary>部门。组织机构</summary>
Int32 DepartmentID { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions XCode/Membership/用户.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ public partial class User
[BindColumn("RoleID", "角色。主要角色", "")]
public Int32 RoleID { get => _RoleID; set { if (OnPropertyChanging("RoleID", value)) { _RoleID = value; OnPropertyChanged("RoleID"); } } }

private Int32[] _RoleIds;
private String _RoleIds;
/// <summary>角色组。次要角色集合</summary>
[DisplayName("角色组")]
[Description("角色组。次要角色集合")]
[DataObjectField(false, false, true, 0)]
[DataObjectField(false, false, true, 200)]
[BindColumn("RoleIds", "角色组。次要角色集合", "")]
public Int32[] RoleIds { get => _RoleIds; set { if (OnPropertyChanging("RoleIds", value)) { _RoleIds = value; OnPropertyChanged("RoleIds"); } } }
public String RoleIds { get => _RoleIds; set { if (OnPropertyChanging("RoleIds", value)) { _RoleIds = value; OnPropertyChanged("RoleIds"); } } }

private Int32 _DepartmentID;
/// <summary>部门。组织机构</summary>
Expand Down Expand Up @@ -320,7 +320,7 @@ public override Object this[String name]
case "Code": _Code = Convert.ToString(value); break;
case "Avatar": _Avatar = Convert.ToString(value); break;
case "RoleID": _RoleID = value.ToInt(); break;
case "RoleIds": _RoleIds = (Int32[])value; break;
case "RoleIds": _RoleIds = Convert.ToString(value); break;
case "DepartmentID": _DepartmentID = value.ToInt(); break;
case "Online": _Online = value.ToBoolean(); break;
case "Enable": _Enable = value.ToBoolean(); break;
Expand Down
49 changes: 0 additions & 49 deletions XUnitTest.XCode/Membership/UserTests.cs

This file was deleted.

0 comments on commit f02283d

Please sign in to comment.