From fa481700414312e300ad61e5201ddb659bf5216c Mon Sep 17 00:00:00 2001 From: 28810 <28810@YEXIANGQIN> Date: Tue, 8 Oct 2019 00:43:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=B1=BB=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=EF=BC=88=E4=B8=8D=E5=BD=B1=E5=93=8D=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FreeSql/DataAnnotations/IndexAttribute.cs | 36 +++++++++++++++++ FreeSql/DataAnnotations/TableAttribute.cs | 30 --------------- FreeSql/FreeSql.xml | 47 +++++++++++++++-------- 3 files changed, 67 insertions(+), 46 deletions(-) create mode 100644 FreeSql/DataAnnotations/IndexAttribute.cs diff --git a/FreeSql/DataAnnotations/IndexAttribute.cs b/FreeSql/DataAnnotations/IndexAttribute.cs new file mode 100644 index 00000000..9115dfd0 --- /dev/null +++ b/FreeSql/DataAnnotations/IndexAttribute.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace FreeSql.DataAnnotations +{ + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] + public class IndexAttribute : Attribute + { + public IndexAttribute(string name, string fields) + { + this.Name = name; + this.Fields = fields; + } + public IndexAttribute(string name, string fields, bool isUnique) + { + this.Name = name; + this.Fields = fields; + this.IsUnique = isUnique; + } + /// + /// 索引名 + /// + public string Name { get; set; } + /// + /// 索引字段,为属性名以逗号分隔,如:Create_time ASC, Title ASC + /// + public string Fields { get; set; } + + internal bool? _IsUnique; + /// + /// 是否唯一 + /// + public bool IsUnique { get => _IsUnique ?? false; set => _IsUnique = value; } + } +} diff --git a/FreeSql/DataAnnotations/TableAttribute.cs b/FreeSql/DataAnnotations/TableAttribute.cs index 18fb2e54..7ec69bb0 100644 --- a/FreeSql/DataAnnotations/TableAttribute.cs +++ b/FreeSql/DataAnnotations/TableAttribute.cs @@ -31,34 +31,4 @@ namespace FreeSql.DataAnnotations internal ConcurrentDictionary _navigates { get; } = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); internal ConcurrentDictionary _indexs { get; } = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); } - - [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] - public class IndexAttribute : Attribute - { - public IndexAttribute(string name, string fields) - { - this.Name = name; - this.Fields = fields; - } - public IndexAttribute(string name, string fields, bool isUnique) - { - this.Name = name; - this.Fields = fields; - this.IsUnique = isUnique; - } - /// - /// 索引名 - /// - public string Name { get; set; } - /// - /// 索引字段,为属性名以逗号分隔,如:Create_time ASC, Title ASC - /// - public string Fields { get; set; } - - internal bool? _IsUnique; - /// - /// 是否唯一 - /// - public bool IsUnique { get => _IsUnique ?? false; set => _IsUnique = value; } - } } diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml index a4a50a9c..6ae63c12 100644 --- a/FreeSql/FreeSql.xml +++ b/FreeSql/FreeSql.xml @@ -152,6 +152,21 @@ + + + 索引名 + + + + + 索引字段,为属性名以逗号分隔,如:Create_time ASC, Title ASC + + + + + 是否唯一 + + 手工绑定 OneToMany、ManyToOne 导航关系 @@ -187,21 +202,6 @@ 禁用 CodeFirst 同步结构迁移 - - - 索引名 - - - - - 索引字段,为属性名以逗号分隔,如:Create_time ASC, Title ASC - - - - - 是否唯一 - - 数据库表名 @@ -1458,7 +1458,8 @@ - 贪婪加载集合的导航属性,其实是分两次查询,ToList 后进行了数据重装 + 贪婪加载集合的导航属性,其实是分两次查询,ToList 后进行了数据重装 + 文档:https://github.com/2881099/FreeSql/wiki/%e8%b4%aa%e5%a9%aa%e5%8a%a0%e8%bd%bd#%E5%AF%BC%E8%88%AA%E5%B1%9E%E6%80%A7-onetomanymanytomany 选择一个集合的导航属性,也可通过 .Where 设置临时的关系映射,还可以 .Take(5) 每个子集合只取5条 @@ -2608,6 +2609,20 @@ + + + 本方法实现从已知的内存 List 数据,进行和 ISelect.IncludeMany 相同功能的贪婪加载 + 示例:new List<Song>(new[] { song1, song2, song3 }).IncludeMany(g.sqlite, a => a.Tags); + 文档:https://github.com/2881099/FreeSql/wiki/%e8%b4%aa%e5%a9%aa%e5%8a%a0%e8%bd%bd#%E5%AF%BC%E8%88%AA%E5%B1%9E%E6%80%A7-onetomanymanytomany + + + + + + 选择一个集合的导航属性,也可通过 .Where 设置临时的关系映射,还可以 .Take(5) 每个子集合只取5条 + 即能 ThenInclude,还可以二次过滤(这个 EFCore 做不到?) + + 使用 and 拼接两个 lambda 表达式