mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 优化 ReadAnonymous 映射类型不一致的容错;
This commit is contained in:
parent
bfed0cd124
commit
27f053f00b
@ -389,5 +389,80 @@
|
||||
验证标志
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:kwlib.department">
|
||||
<summary>
|
||||
部门表
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:kwlib.department.id">
|
||||
<summary>
|
||||
部门ID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:kwlib.department.Employees">
|
||||
<summary>
|
||||
员工列表 对应employee.deptid
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:kwlib.department.supdeptid">
|
||||
<summary>
|
||||
上级部门ID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:kwlib.department.parentdepartments">
|
||||
<summary>
|
||||
上级部门对象
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:kwlib.department.managerid">
|
||||
<summary>
|
||||
部门主管ID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:kwlib.department.manager">
|
||||
<summary>
|
||||
部门主管对象
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:kwlib.department.childDepartments">
|
||||
<summary>
|
||||
下级部门列表
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:kwlib.department.deptcode">
|
||||
<summary>
|
||||
部门代码
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:kwlib.department.deptname">
|
||||
<summary>
|
||||
部门名称
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:kwlib.employee">
|
||||
<summary>
|
||||
员工表
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:kwlib.employee.id">
|
||||
<summary>
|
||||
员工ID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:kwlib.employee.parentManager">
|
||||
<summary>
|
||||
上级主管对象
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:kwlib.employee.Employees">
|
||||
<summary>
|
||||
下级员工列表
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:kwlib.employee.Department">
|
||||
<summary>
|
||||
部门对象
|
||||
</summary>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
79
FreeSql.Tests/FreeSql.Tests/Other/kwlib/department.cs
Normal file
79
FreeSql.Tests/FreeSql.Tests/Other/kwlib/department.cs
Normal file
@ -0,0 +1,79 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace kwlib
|
||||
{
|
||||
/// <summary>
|
||||
/// 部门表
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[Index("部门代码deptcode唯一", "deptcode", true)]
|
||||
public class department
|
||||
{
|
||||
/// <summary>
|
||||
/// 部门ID
|
||||
/// </summary>
|
||||
[Column(IsPrimary = true, IsIdentity = true)]
|
||||
public int id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 员工列表 对应employee.deptid
|
||||
/// </summary>
|
||||
[Navigate("deptid")]
|
||||
public List<employee> Employees { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上级部门ID
|
||||
/// </summary>
|
||||
public int? supdeptid { get; set; }
|
||||
/// <summary>
|
||||
/// 上级部门对象
|
||||
/// </summary>
|
||||
[Navigate("supdeptid")]
|
||||
public department parentdepartments { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 部门主管ID
|
||||
/// </summary>
|
||||
public int? managerid { get; set; }
|
||||
/// <summary>
|
||||
/// 部门主管对象
|
||||
/// </summary>
|
||||
[Navigate("managerid")]
|
||||
public employee manager { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 下级部门列表
|
||||
/// </summary>
|
||||
[Navigate("supdeptid")]
|
||||
public List<department> childDepartments { get; set; }
|
||||
|
||||
|
||||
[Navigate(ManyToMany = typeof(department_employee))]
|
||||
public List<employee> employees22 { get; set; }
|
||||
|
||||
|
||||
#region MyRegion
|
||||
/// <summary>
|
||||
/// 部门代码
|
||||
/// </summary>
|
||||
public string deptcode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 部门名称
|
||||
/// </summary>
|
||||
public string deptname { get; set; }
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace kwlib
|
||||
{
|
||||
public class department_employee
|
||||
{
|
||||
public int departmentId { get; set; }
|
||||
public int employeeId { get; set; }
|
||||
|
||||
[Navigate("departmentId")]
|
||||
public department dept { get; set; }
|
||||
[Navigate("employeeId")]
|
||||
public employee empe { get; set; }
|
||||
}
|
||||
}
|
171
FreeSql.Tests/FreeSql.Tests/Other/kwlib/employee.cs
Normal file
171
FreeSql.Tests/FreeSql.Tests/Other/kwlib/employee.cs
Normal file
@ -0,0 +1,171 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace kwlib
|
||||
{
|
||||
/// <summary>
|
||||
/// 员工表
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[Index("员工代码empcode唯一", "empcode", true)]
|
||||
public class employee
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 员工ID
|
||||
/// </summary>
|
||||
[Column(IsPrimary = true, IsIdentity = true)]
|
||||
[System.ComponentModel.DisplayName("员工ID ")]
|
||||
public int id { get; set; }
|
||||
|
||||
[System.ComponentModel.DisplayName("上级主管ID")]
|
||||
/// <summary>
|
||||
/// 上级主管ID
|
||||
/// </summary>
|
||||
public int? managerid { get; set; }
|
||||
/// <summary>
|
||||
/// 上级主管对象
|
||||
/// </summary>
|
||||
[Navigate("managerid")]
|
||||
public employee parentManager { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 下级员工列表
|
||||
/// </summary>
|
||||
[Navigate("managerid")]
|
||||
public List<employee> Employees { get; set; }
|
||||
|
||||
|
||||
[Navigate(ManyToMany = typeof(department_employee))]
|
||||
public List<department> departments { get; set; }
|
||||
|
||||
[System.ComponentModel.DisplayName("部门ID ")]
|
||||
/// <summary>
|
||||
/// 部门ID
|
||||
/// </summary>
|
||||
public int? deptid { get; set; }
|
||||
/// <summary>
|
||||
/// 部门对象
|
||||
/// </summary>
|
||||
[Navigate("deptid")]
|
||||
public department Department { get; set; }
|
||||
|
||||
|
||||
|
||||
[System.ComponentModel.DisplayName("员工工号")]
|
||||
/// <summary>
|
||||
/// 员工工号
|
||||
/// </summary>
|
||||
public String empcode { get; set; }
|
||||
|
||||
|
||||
|
||||
[System.ComponentModel.DisplayName("员工姓名")]
|
||||
/// <summary>
|
||||
/// 员工姓名
|
||||
/// </summary>
|
||||
public String empname { get; set; }
|
||||
|
||||
|
||||
[System.ComponentModel.DisplayName("地址")]
|
||||
/// <summary>
|
||||
/// 地址
|
||||
/// </summary>
|
||||
public String address { get; set; }
|
||||
|
||||
|
||||
[System.ComponentModel.DisplayName("工卡ID ")]
|
||||
/// <summary>
|
||||
/// 工卡ID
|
||||
/// </summary>
|
||||
|
||||
public String cardid { get; set; }
|
||||
|
||||
|
||||
[System.ComponentModel.DisplayName("邮件地址 ")]
|
||||
/// <summary>
|
||||
/// 邮件地址
|
||||
/// </summary>
|
||||
|
||||
public String email { get; set; }
|
||||
|
||||
|
||||
[System.ComponentModel.DisplayName("合同日期")]
|
||||
/// <summary>
|
||||
/// 合同日期
|
||||
/// </summary>
|
||||
|
||||
public DateTime? hetongdate { get; set; }
|
||||
|
||||
|
||||
[System.ComponentModel.DisplayName("籍贯")]
|
||||
/// <summary>
|
||||
/// 籍贯
|
||||
/// </summary>
|
||||
|
||||
public String homeaddress { get; set; }
|
||||
|
||||
|
||||
[System.ComponentModel.DisplayName("入职时间")]
|
||||
/// <summary>
|
||||
/// 入职时间
|
||||
/// </summary>
|
||||
|
||||
public DateTime jointime { get; set; }
|
||||
|
||||
|
||||
[System.ComponentModel.DisplayName("离职日期")]
|
||||
/// <summary>
|
||||
/// 离职日期
|
||||
/// </summary>
|
||||
public DateTime? leavedate { get; set; }
|
||||
|
||||
|
||||
[System.ComponentModel.DisplayName("登录密码")]
|
||||
/// <summary>
|
||||
/// 登录密码
|
||||
/// </summary>
|
||||
public String loginpass { get; set; }
|
||||
|
||||
|
||||
|
||||
[System.ComponentModel.DisplayName("电话")]
|
||||
/// <summary>
|
||||
/// 电话
|
||||
/// </summary>
|
||||
public String phone { get; set; }
|
||||
|
||||
|
||||
[System.ComponentModel.DisplayName("相片地址")]
|
||||
/// <summary>
|
||||
/// 相片地址
|
||||
/// </summary>
|
||||
|
||||
public String picurl { get; set; }
|
||||
|
||||
|
||||
|
||||
[System.ComponentModel.DisplayName("身份证")]
|
||||
/// <summary>
|
||||
/// 身份证
|
||||
/// </summary>
|
||||
|
||||
public String sfz { get; set; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -798,9 +798,15 @@ namespace FreeSql.Tests.Sqlite
|
||||
};
|
||||
var query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).AsTable(tableRule).AsTable(tableRule2);
|
||||
var sql = query.ToSql();
|
||||
var sql2 = query.ToSql("count(1)");
|
||||
var count2 = query.ToList<int>("count(1)");
|
||||
|
||||
|
||||
|
||||
query = select.AsTable((type, oldname) => "table_1").AsTable((type, oldname) => "table_2").AsTable((type, oldname) => "table_3");
|
||||
sql = query.ToSql(a => a.Id);
|
||||
sql2 = query.ToSql("count(1)");
|
||||
count2 = query.ToList<int>("count(1)");
|
||||
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a.Type<70><65>a.Type.Parent <20><><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
@ -424,9 +424,31 @@ namespace FreeSql.Tests
|
||||
public new int Id { get; set; }
|
||||
}
|
||||
|
||||
public class TestUpdateModel
|
||||
{
|
||||
public string F_EmpId { get; set; }
|
||||
public TestUpdateModelEnum F_RoleType { get; set; }
|
||||
public TestUpdateModelEnum F_UseType { get; set; }
|
||||
}
|
||||
public enum TestUpdateModelEnum { x1, x2, x3 }
|
||||
|
||||
[Fact]
|
||||
public void Test1()
|
||||
{
|
||||
var _model = new TestUpdateModel {
|
||||
F_EmpId = "xx11",
|
||||
F_RoleType = TestUpdateModelEnum.x2,
|
||||
F_UseType = TestUpdateModelEnum.x3
|
||||
};
|
||||
var testsql2008 = g.sqlserver.Update<TestUpdateModel>()
|
||||
.Where(a => a.F_EmpId == _model.F_EmpId)
|
||||
.Set(a => new TestUpdateModel
|
||||
{
|
||||
F_RoleType = _model.F_RoleType,
|
||||
F_UseType = _model.F_UseType
|
||||
}).ToSql();
|
||||
|
||||
|
||||
g.sqlserver.Select<NewsArticle>();
|
||||
|
||||
g.sqlite.Update<Model1>(1).NoneParameter().Set(a => a.title, null).ExecuteAffrows();
|
||||
@ -706,7 +728,14 @@ namespace FreeSql.Tests
|
||||
OptionsEntity02 = false,
|
||||
OptionsEntity04 = testarray[0]
|
||||
}).ToSql();
|
||||
|
||||
var tbidsql3 = g.sqlite.Update<TaskBuild>().Where(a => a.TemplatesId == tbid)
|
||||
.Set(a => new TaskBuild
|
||||
{
|
||||
FileName = "111",
|
||||
TaskName = a.TaskName + "333",
|
||||
OptionsEntity02 = false,
|
||||
OptionsEntity04 = testarray[0]
|
||||
}).ToSql();
|
||||
|
||||
var dkdkdkd = g.oracle.Select<Templates>().ToList();
|
||||
|
||||
|
@ -12,6 +12,7 @@ using System.Threading.Tasks;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Threading;
|
||||
using System.Data.SqlClient;
|
||||
using kwlib;
|
||||
|
||||
namespace FreeSql.Tests
|
||||
{
|
||||
@ -202,6 +203,8 @@ namespace FreeSql.Tests
|
||||
[Fact]
|
||||
public void Test02()
|
||||
{
|
||||
var tekset = g.sqlite.Select<employee>().IncludeMany(a => a.departments).ToList();
|
||||
|
||||
g.sqlserver.Delete<TBatInst>().Where("1=1").ExecuteAffrows();
|
||||
g.mysql.Delete<TBatInst>().Where("1=1").ExecuteAffrows();
|
||||
g.pgsql.Delete<TBatInst>().Where("1=1").ExecuteAffrows();
|
||||
|
@ -124,7 +124,7 @@ namespace FreeSql.Internal
|
||||
{
|
||||
Property = dtoProp,
|
||||
CsName = dtoProp.Name,
|
||||
CsType = dtoProp.PropertyType,
|
||||
CsType = trydtocol.CsType, // dtoProp.PropertyType,
|
||||
MapType = trydtocol.Attribute.MapType
|
||||
};
|
||||
parent.Childs.Add(child);
|
||||
@ -195,7 +195,7 @@ namespace FreeSql.Internal
|
||||
{
|
||||
Property = dtoProp,
|
||||
CsName = dtoProp.Name,
|
||||
CsType = dtoProp.PropertyType,
|
||||
CsType = trydtocol.CsType, //dtoProp.PropertyType,
|
||||
MapType = trydtocol.Attribute.MapType
|
||||
};
|
||||
parent.Childs.Add(child);
|
||||
@ -227,11 +227,17 @@ namespace FreeSql.Internal
|
||||
if (notRead)
|
||||
{
|
||||
++index;
|
||||
if (parent.Property != null)
|
||||
return Utils.GetDataReaderValue(parent.Property.PropertyType, null);
|
||||
return Utils.GetDataReaderValue(parent.CsType, null);
|
||||
}
|
||||
if (parent.CsType == parent.MapType)
|
||||
return Utils.GetDataReaderValue(parent.CsType, dr.GetValue(++index));
|
||||
return Utils.GetDataReaderValue(parent.CsType, Utils.GetDataReaderValue(parent.MapType, dr.GetValue(++index)));
|
||||
object objval = dr.GetValue(++index);
|
||||
if (parent.CsType != parent.MapType)
|
||||
objval = Utils.GetDataReaderValue(parent.MapType, objval);
|
||||
objval = Utils.GetDataReaderValue(parent.CsType, objval);
|
||||
if (parent.Property != null && parent.CsType != parent.Property.PropertyType)
|
||||
objval = Utils.GetDataReaderValue(parent.Property.PropertyType, objval);
|
||||
return objval;
|
||||
}
|
||||
switch (parent.ConsturctorType)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user