From 5f3aaac19bd187c70c1c215a2c7d999c0df8a646 Mon Sep 17 00:00:00 2001 From: 28810 <28810@YEXIANGQIN> Date: Fri, 17 May 2019 15:16:08 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8D=20IncludeMany=20ManyToMa?= =?UTF-8?q?ny=EF=BC=8C=E8=8B=A5=E4=B8=AD=E9=97=B4=E8=A1=A8=E6=9C=AA?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20=E5=BB=B6=E6=97=B6=E5=8A=A0=E8=BD=BD=20?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E5=8A=9F=E8=83=BD=E6=97=B6=EF=BC=8C=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E7=9A=84=20bug=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FreeSql.Tests/FreeSql.Tests.csproj | 2 +- FreeSql.Tests/UnitTest2.cs | 172 ++++++++++++++++++ FreeSql/FreeSql.csproj | 2 +- .../SelectProvider/Select1Provider.cs | 2 +- 4 files changed, 175 insertions(+), 3 deletions(-) create mode 100644 FreeSql.Tests/UnitTest2.cs diff --git a/FreeSql.Tests/FreeSql.Tests.csproj b/FreeSql.Tests/FreeSql.Tests.csproj index d12b032a..e43255e6 100644 --- a/FreeSql.Tests/FreeSql.Tests.csproj +++ b/FreeSql.Tests/FreeSql.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/FreeSql.Tests/UnitTest2.cs b/FreeSql.Tests/UnitTest2.cs new file mode 100644 index 00000000..1b1b056a --- /dev/null +++ b/FreeSql.Tests/UnitTest2.cs @@ -0,0 +1,172 @@ +using FreeSql.DataAnnotations; +using FreeSql; +using System; +using System.Collections.Generic; +using Xunit; +using System.Linq; +using Newtonsoft.Json.Linq; +using NpgsqlTypes; +using Npgsql.LegacyPostgis; +using System.Linq.Expressions; +using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations; + +namespace FreeSql.Tests { + public class UnitTest2 { + + public partial class SysModulePermission { + /// + /// 菜单权限ID + /// + [Column(IsPrimary = true)] public String SysModulePermissionId { get; set; } + + /// + /// 菜单主键ID + /// + public String SysModuleId { get; set; } + + /// + /// 按钮主键ID + /// + public String SysModuleButtonId { get; set; } + + /// + /// 菜单权限 + /// + public Int32 Status { get; set; } + } + public partial class SysModule { + /// + /// 主键 + /// + [Column(IsPrimary = true)] + public String SysModuleId { get; set; } + + /// + /// 父级ID + /// + public String ParentId { get; set; } + + /// + /// 名称 + /// + public String Name { get; set; } + + /// + /// 图标 + /// + public String Icon { get; set; } + + /// + /// 链接地址 + /// + public String UrlAddress { get; set; } + + /// + /// 是否公开 + /// + public Int32 IsShow { get; set; } + + /// + /// 排序 + /// + public Int32? Sort { get; set; } + + /// + /// 备注 + /// + public String Description { get; set; } + + /// + /// 创建日期 + /// + public DateTime CreateTime { get; set; } + + } + public partial class SysModuleButton { + /// + /// 按钮主键 + /// + [Column(IsPrimary = true)] + public String SysModuleButtonId { get; set; } + + /// + /// 名称 + /// + public String Name { get; set; } + + /// + /// 事件名称 + /// + public String EventName { get; set; } + + /// + /// 编码 + /// + public String EnCode { get; set; } + + /// + /// 图标 + /// + public String Icon { get; set; } + + /// + /// 排序 + /// + public Int32? Sort { get; set; } + + /// + /// 创建日期 + /// + public DateTime CreateTime { get; set; } + } + partial class SysModulePermission { + public SysModuleButton Button { get; set; } + } + partial class SysModule { + public List Permissions { get; set; } + } + partial class SysModuleButton { + } + + [Fact] + public void Test02() { + + g.sqlite.Delete().Where("1=1").ExecuteAffrows(); + g.sqlite.Delete().Where("1=1").ExecuteAffrows(); + g.sqlite.Delete().Where("1=1").ExecuteAffrows(); + + var menu1 = new SysModule { SysModuleId = "menu1", Name = "菜单1" }; + var menu2 = new SysModule { SysModuleId = "menu2", Name = "菜单2" }; + g.sqlite.Insert(new[] { menu1, menu2 }).ExecuteAffrows(); + + var button1 = new SysModuleButton { SysModuleButtonId = "button1", Name = "添加" }; + var button2 = new SysModuleButton { SysModuleButtonId = "button2", Name = "修改" }; + var button3 = new SysModuleButton { SysModuleButtonId = "button3", Name = "删除" }; + var button4 = new SysModuleButton { SysModuleButtonId = "button4", Name = "查询" }; + g.sqlite.Insert(new[] { button1, button2, button3, button4 }).ExecuteAffrows(); + + g.sqlite.Insert(new[] { + new SysModulePermission { SysModulePermissionId = "menu1_button1", SysModuleId = menu1.SysModuleId, SysModuleButtonId = button1.SysModuleButtonId }, + new SysModulePermission { SysModulePermissionId = "menu1_button2", SysModuleId = menu1.SysModuleId, SysModuleButtonId = button2.SysModuleButtonId }, + new SysModulePermission { SysModulePermissionId = "menu1_button3", SysModuleId = menu1.SysModuleId, SysModuleButtonId = button3.SysModuleButtonId }, + new SysModulePermission { SysModulePermissionId = "menu1_button4", SysModuleId = menu1.SysModuleId, SysModuleButtonId = button4.SysModuleButtonId }, + + new SysModulePermission { SysModulePermissionId = "menu2_button1", SysModuleId = menu2.SysModuleId, SysModuleButtonId = button1.SysModuleButtonId }, + new SysModulePermission { SysModulePermissionId = "menu2_button2", SysModuleId = menu2.SysModuleId, SysModuleButtonId = button2.SysModuleButtonId }, + new SysModulePermission { SysModulePermissionId = "menu2_button3", SysModuleId = menu2.SysModuleId, SysModuleButtonId = button3.SysModuleButtonId }, + new SysModulePermission { SysModulePermissionId = "menu2_button4", SysModuleId = menu2.SysModuleId, SysModuleButtonId = button4.SysModuleButtonId }, + }).ExecuteAffrows(); + + //var list = g.sqlite.Select() + // .IncludeMany(m => m.Buttons) + // .Page(1, 10) + // .ToList(); + + var list = g.sqlite.Select() + .IncludeMany(m => m.Permissions.Where(p => p.SysModuleId == m.SysModuleId), + then => then.LeftJoin(p => p.Button.SysModuleButtonId == p.SysModuleButtonId)) + .ToList(); + } + } +} diff --git a/FreeSql/FreeSql.csproj b/FreeSql/FreeSql.csproj index ea3f988c..fbd4d362 100644 --- a/FreeSql/FreeSql.csproj +++ b/FreeSql/FreeSql.csproj @@ -2,7 +2,7 @@ netstandard2.0 - 0.5.19 + 0.5.20 true YeXiangQin FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite. diff --git a/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs b/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs index 07c08274..4e9f9017 100644 --- a/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs +++ b/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs @@ -658,7 +658,7 @@ namespace FreeSql.Internal.CommonProvider { var field = new StringBuilder(); var read = new ReadAnonymousTypeInfo(); read.ConsturctorType = ReadAnonymousTypeInfoConsturctorType.Properties; - read.Consturctor = tbrefMid.TypeLazy.GetConstructor(new Type[0]); + read.Consturctor = (tbrefMid.TypeLazy ?? tbrefMid.Type).GetConstructor(new Type[0]); read.Table = tbrefMid; foreach (var col in tbrefMid.Columns.Values) { if (tbref.MiddleColumns.Where(a => a.CsName == col.CsName).Any() == false) continue;