From 27f053f00be75d9dc4eaeb9eced659f3fe181658 Mon Sep 17 00:00:00 2001 From: 28810 <28810@YEXIANGQIN> Date: Fri, 29 Nov 2019 17:56:06 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BC=98=E5=8C=96=20ReadAnonymous=20?= =?UTF-8?q?=E6=98=A0=E5=B0=84=E7=B1=BB=E5=9E=8B=E4=B8=8D=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E5=AE=B9=E9=94=99=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FreeSql.Tests/FreeSql.Tests/FreeSql.Tests.xml | 75 ++++++++ .../FreeSql.Tests/Other/kwlib/department.cs | 79 ++++++++ .../Other/kwlib/department_employee.cs | 20 ++ .../FreeSql.Tests/Other/kwlib/employee.cs | 171 ++++++++++++++++++ .../Sqlite/Curd/SqliteSelectTest.cs | 6 + FreeSql.Tests/FreeSql.Tests/UnitTest1.cs | 31 +++- FreeSql.Tests/FreeSql.Tests/UnitTest2.cs | 3 + FreeSql/Internal/CommonExpression.cs | 16 +- 8 files changed, 395 insertions(+), 6 deletions(-) create mode 100644 FreeSql.Tests/FreeSql.Tests/Other/kwlib/department.cs create mode 100644 FreeSql.Tests/FreeSql.Tests/Other/kwlib/department_employee.cs create mode 100644 FreeSql.Tests/FreeSql.Tests/Other/kwlib/employee.cs diff --git a/FreeSql.Tests/FreeSql.Tests/FreeSql.Tests.xml b/FreeSql.Tests/FreeSql.Tests/FreeSql.Tests.xml index d0b42783..5b80bfb0 100644 --- a/FreeSql.Tests/FreeSql.Tests/FreeSql.Tests.xml +++ b/FreeSql.Tests/FreeSql.Tests/FreeSql.Tests.xml @@ -389,5 +389,80 @@ 验证标志 + + + 部门表 + + + + + 部门ID + + + + + 员工列表 对应employee.deptid + + + + + 上级部门ID + + + + + 上级部门对象 + + + + + 部门主管ID + + + + + 部门主管对象 + + + + + 下级部门列表 + + + + + 部门代码 + + + + + 部门名称 + + + + + 员工表 + + + + + 员工ID + + + + + 上级主管对象 + + + + + 下级员工列表 + + + + + 部门对象 + + diff --git a/FreeSql.Tests/FreeSql.Tests/Other/kwlib/department.cs b/FreeSql.Tests/FreeSql.Tests/Other/kwlib/department.cs new file mode 100644 index 00000000..1f3a5ccf --- /dev/null +++ b/FreeSql.Tests/FreeSql.Tests/Other/kwlib/department.cs @@ -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 +{ + /// + /// 部门表 + /// + [Serializable] + [Index("部门代码deptcode唯一", "deptcode", true)] + public class department + { + /// + /// 部门ID + /// + [Column(IsPrimary = true, IsIdentity = true)] + public int id { get; set; } + + /// + /// 员工列表 对应employee.deptid + /// + [Navigate("deptid")] + public List Employees { get; set; } + + /// + /// 上级部门ID + /// + public int? supdeptid { get; set; } + /// + /// 上级部门对象 + /// + [Navigate("supdeptid")] + public department parentdepartments { get; set; } + + /// + /// 部门主管ID + /// + public int? managerid { get; set; } + /// + /// 部门主管对象 + /// + [Navigate("managerid")] + public employee manager { get; set; } + + + /// + /// 下级部门列表 + /// + [Navigate("supdeptid")] + public List childDepartments { get; set; } + + + [Navigate(ManyToMany = typeof(department_employee))] + public List employees22 { get; set; } + + + #region MyRegion + /// + /// 部门代码 + /// + public string deptcode { get; set; } + + /// + /// 部门名称 + /// + public string deptname { get; set; } + #endregion + + + + + } + +} \ No newline at end of file diff --git a/FreeSql.Tests/FreeSql.Tests/Other/kwlib/department_employee.cs b/FreeSql.Tests/FreeSql.Tests/Other/kwlib/department_employee.cs new file mode 100644 index 00000000..8c20b8e1 --- /dev/null +++ b/FreeSql.Tests/FreeSql.Tests/Other/kwlib/department_employee.cs @@ -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; } + } +} diff --git a/FreeSql.Tests/FreeSql.Tests/Other/kwlib/employee.cs b/FreeSql.Tests/FreeSql.Tests/Other/kwlib/employee.cs new file mode 100644 index 00000000..9b292e89 --- /dev/null +++ b/FreeSql.Tests/FreeSql.Tests/Other/kwlib/employee.cs @@ -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 +{ + /// + /// 员工表 + /// + [Serializable] + [Index("员工代码empcode唯一", "empcode", true)] + public class employee + { + + + /// + /// 员工ID + /// + [Column(IsPrimary = true, IsIdentity = true)] + [System.ComponentModel.DisplayName("员工ID ")] + public int id { get; set; } + + [System.ComponentModel.DisplayName("上级主管ID")] + /// + /// 上级主管ID + /// + public int? managerid { get; set; } + /// + /// 上级主管对象 + /// + [Navigate("managerid")] + public employee parentManager { get; set; } + + /// + /// 下级员工列表 + /// + [Navigate("managerid")] + public List Employees { get; set; } + + + [Navigate(ManyToMany = typeof(department_employee))] + public List departments { get; set; } + + [System.ComponentModel.DisplayName("部门ID ")] + /// + /// 部门ID + /// + public int? deptid { get; set; } + /// + /// 部门对象 + /// + [Navigate("deptid")] + public department Department { get; set; } + + + + [System.ComponentModel.DisplayName("员工工号")] + /// + /// 员工工号 + /// + public String empcode { get; set; } + + + + [System.ComponentModel.DisplayName("员工姓名")] + /// + /// 员工姓名 + /// + public String empname { get; set; } + + + [System.ComponentModel.DisplayName("地址")] + /// + /// 地址 + /// + public String address { get; set; } + + + [System.ComponentModel.DisplayName("工卡ID ")] + /// + /// 工卡ID + /// + + public String cardid { get; set; } + + + [System.ComponentModel.DisplayName("邮件地址 ")] + /// + /// 邮件地址 + /// + + public String email { get; set; } + + + [System.ComponentModel.DisplayName("合同日期")] + /// + /// 合同日期 + /// + + public DateTime? hetongdate { get; set; } + + + [System.ComponentModel.DisplayName("籍贯")] + /// + /// 籍贯 + /// + + public String homeaddress { get; set; } + + + [System.ComponentModel.DisplayName("入职时间")] + /// + /// 入职时间 + /// + + public DateTime jointime { get; set; } + + + [System.ComponentModel.DisplayName("离职日期")] + /// + /// 离职日期 + /// + public DateTime? leavedate { get; set; } + + + [System.ComponentModel.DisplayName("登录密码")] + /// + /// 登录密码 + /// + public String loginpass { get; set; } + + + + [System.ComponentModel.DisplayName("电话")] + /// + /// 电话 + /// + public String phone { get; set; } + + + [System.ComponentModel.DisplayName("相片地址")] + /// + /// 相片地址 + /// + + public String picurl { get; set; } + + + + [System.ComponentModel.DisplayName("身份证")] + /// + /// 身份证 + /// + + public String sfz { get; set; } + + + } + + + + + + + + + +} diff --git a/FreeSql.Tests/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs b/FreeSql.Tests/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs index 1d32c36c..d2e262ca 100644 --- a/FreeSql.Tests/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs +++ b/FreeSql.Tests/FreeSql.Tests/Sqlite/Curd/SqliteSelectTest.cs @@ -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("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("count(1)"); //����е�������a.Type��a.Type.Parent ���ǵ������� diff --git a/FreeSql.Tests/FreeSql.Tests/UnitTest1.cs b/FreeSql.Tests/FreeSql.Tests/UnitTest1.cs index b6080caf..1ccd662d 100644 --- a/FreeSql.Tests/FreeSql.Tests/UnitTest1.cs +++ b/FreeSql.Tests/FreeSql.Tests/UnitTest1.cs @@ -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() + .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(); g.sqlite.Update(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().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().ToList(); diff --git a/FreeSql.Tests/FreeSql.Tests/UnitTest2.cs b/FreeSql.Tests/FreeSql.Tests/UnitTest2.cs index fb7f5ac3..3426816e 100644 --- a/FreeSql.Tests/FreeSql.Tests/UnitTest2.cs +++ b/FreeSql.Tests/FreeSql.Tests/UnitTest2.cs @@ -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().IncludeMany(a => a.departments).ToList(); + g.sqlserver.Delete().Where("1=1").ExecuteAffrows(); g.mysql.Delete().Where("1=1").ExecuteAffrows(); g.pgsql.Delete().Where("1=1").ExecuteAffrows(); diff --git a/FreeSql/Internal/CommonExpression.cs b/FreeSql/Internal/CommonExpression.cs index b31fc599..d767c504 100644 --- a/FreeSql/Internal/CommonExpression.cs +++ b/FreeSql/Internal/CommonExpression.cs @@ -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) {