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 表达式