diff --git a/Directory.Build.props b/Directory.Build.props
index b648c47c..df4b1f61 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -11,7 +11,7 @@
diff --git a/Extensions/FreeSql.Extensions.AggregateRoot/FreeSql.Extensions.AggregateRoot.csproj b/Extensions/FreeSql.Extensions.AggregateRoot/FreeSql.Extensions.AggregateRoot.csproj
index 6c145249..492b0057 100644
--- a/Extensions/FreeSql.Extensions.AggregateRoot/FreeSql.Extensions.AggregateRoot.csproj
+++ b/Extensions/FreeSql.Extensions.AggregateRoot/FreeSql.Extensions.AggregateRoot.csproj
@@ -31,7 +31,11 @@
-
+
+
+
+ net40
+
diff --git a/Extensions/FreeSql.Extensions.AggregateRoot/FreeSql.Extensions.AggregateRoot.xml b/Extensions/FreeSql.Extensions.AggregateRoot/FreeSql.Extensions.AggregateRoot.xml
index 75b8c707..eb26af16 100644
--- a/Extensions/FreeSql.Extensions.AggregateRoot/FreeSql.Extensions.AggregateRoot.xml
+++ b/Extensions/FreeSql.Extensions.AggregateRoot/FreeSql.Extensions.AggregateRoot.xml
@@ -1,21 +1,52 @@
- FreeSql.Extensions.JsonMap
+ FreeSql.Extensions.AggregateRoot
-
+
- When the entity class property is , map storage in JSON format.
- 当实体类属性为【对象】时,以 JSON 形式映射存储
+ 设置 AggregateRootRepository 边界范围
+ 在边界范围之内的规则 :
+ 1、OneToOne/OneToMany/ManyToMany(中间表) 可以查询、可以增删改
+ 2、ManyToOne/ManyToMany外部表/PgArrayToMany 只可以查询,不支持增删改(会被忽略)
-
+
- When the entity class property is and the attribute is marked as , map storage in JSON format.
- 当实体类属性为【对象】时,并且标记特性 [JsonMap] 时,该属性将以JSON形式映射存储
+ 边界是否终止
+
+
+
+
+ 边界是否终止向下探测
+
+
+
+
+ 默认:创建查询对象(递归包含 Include/IncludeMany 边界之内的导航属性)
+ 重写:使用
+
+
+
+
+ 创建查询对象(纯净)
+ _
+ 聚合根内关系较复杂时,获取 Include/IncludeMany 字符串代码,方便二次开发
+ string code = AggregateRootUtils.GetAutoIncludeQueryStaicCode(null, fsql, typeof(Order))
+
+
+
+
+ 创建查询对象(递归包含 Include/IncludeMany 边界之内的导航属性)
+
+
+ ISelect.TrackToList 委托,数据返回后自动 Attach
+
+
+
diff --git a/Extensions/FreeSql.Extensions.BaseEntity/FreeSql.Extensions.BaseEntity.csproj b/Extensions/FreeSql.Extensions.BaseEntity/FreeSql.Extensions.BaseEntity.csproj
index dd7c1c20..14c832bc 100644
--- a/Extensions/FreeSql.Extensions.BaseEntity/FreeSql.Extensions.BaseEntity.csproj
+++ b/Extensions/FreeSql.Extensions.BaseEntity/FreeSql.Extensions.BaseEntity.csproj
@@ -19,7 +19,7 @@
key.snk
false
latest
- 3.2.667
+ 3.2.668
diff --git a/Extensions/FreeSql.Extensions.JsonMap/FreeSql.Extensions.JsonMap.csproj b/Extensions/FreeSql.Extensions.JsonMap/FreeSql.Extensions.JsonMap.csproj
index 6d1ebab7..e4ae462d 100644
--- a/Extensions/FreeSql.Extensions.JsonMap/FreeSql.Extensions.JsonMap.csproj
+++ b/Extensions/FreeSql.Extensions.JsonMap/FreeSql.Extensions.JsonMap.csproj
@@ -18,7 +18,7 @@
true
key.snk
false
- 3.2.667
+ 3.2.668
diff --git a/Extensions/FreeSql.Extensions.LazyLoading/FreeSql.Extensions.LazyLoading.csproj b/Extensions/FreeSql.Extensions.LazyLoading/FreeSql.Extensions.LazyLoading.csproj
index 157117c1..532df3f2 100644
--- a/Extensions/FreeSql.Extensions.LazyLoading/FreeSql.Extensions.LazyLoading.csproj
+++ b/Extensions/FreeSql.Extensions.LazyLoading/FreeSql.Extensions.LazyLoading.csproj
@@ -15,7 +15,7 @@
$(AssemblyName)
true
true
- 3.2.667
+ 3.2.668
diff --git a/Extensions/FreeSql.Extensions.Linq/FreeSql.Extensions.Linq.csproj b/Extensions/FreeSql.Extensions.Linq/FreeSql.Extensions.Linq.csproj
index 21979675..fc9acdbf 100644
--- a/Extensions/FreeSql.Extensions.Linq/FreeSql.Extensions.Linq.csproj
+++ b/Extensions/FreeSql.Extensions.Linq/FreeSql.Extensions.Linq.csproj
@@ -18,7 +18,7 @@
true
key.snk
false
- 3.2.667
+ 3.2.668
diff --git a/Extensions/FreeSql.Generator/FreeSql.Generator.csproj b/Extensions/FreeSql.Generator/FreeSql.Generator.csproj
index f20e00e0..0b93164f 100644
--- a/Extensions/FreeSql.Generator/FreeSql.Generator.csproj
+++ b/Extensions/FreeSql.Generator/FreeSql.Generator.csproj
@@ -13,7 +13,7 @@
https://github.com/2881099/FreeSql
https://github.com/2881099/FreeSql
FreeSql DbFirst 实体生成器
- 3.2.667
+ 3.2.668
diff --git a/FreeSql-DbContext.sln b/FreeSql-DbContext.sln
index c98618ed..b1b0fe45 100644
--- a/FreeSql-DbContext.sln
+++ b/FreeSql-DbContext.sln
@@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Provider.Sqlite", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Tests.DbContext2", "FreeSql.Tests\FreeSql.Tests.DbContext2\FreeSql.Tests.DbContext2.csproj", "{5B0AFA8E-D367-4D30-85C0-107DACB0FF49}"
EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Extensions.AggregateRoot", "Extensions\FreeSql.Extensions.AggregateRoot\FreeSql.Extensions.AggregateRoot.csproj", "{B8F84E4F-46F2-4048-B79B-49F0B8A95335}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -39,6 +41,10 @@ Global
{5B0AFA8E-D367-4D30-85C0-107DACB0FF49}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B0AFA8E-D367-4D30-85C0-107DACB0FF49}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B0AFA8E-D367-4D30-85C0-107DACB0FF49}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B8F84E4F-46F2-4048-B79B-49F0B8A95335}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B8F84E4F-46F2-4048-B79B-49F0B8A95335}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B8F84E4F-46F2-4048-B79B-49F0B8A95335}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B8F84E4F-46F2-4048-B79B-49F0B8A95335}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/FreeSql.All/FreeSql.All.csproj b/FreeSql.All/FreeSql.All.csproj
index 0e34a197..3d40a7b1 100644
--- a/FreeSql.All/FreeSql.All.csproj
+++ b/FreeSql.All/FreeSql.All.csproj
@@ -17,7 +17,7 @@
true
key.snk
false
- 3.2.667
+ 3.2.668
diff --git a/FreeSql.DbContext/AggregateRootRepository/AggregateRootBoundaryAttribute.cs b/FreeSql.DbContext/AggregateRootRepository/AggregateRootBoundaryAttribute.cs
deleted file mode 100644
index a2603b44..00000000
--- a/FreeSql.DbContext/AggregateRootRepository/AggregateRootBoundaryAttribute.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using System;
-using System.Linq;
-
-namespace FreeSql.DataAnnotations
-{
-
- ///
- /// 设置 AggregateRootRepository 边界范围
- /// 在边界范围之内的规则 :
- /// 1、OneToOne/OneToMany/ManyToMany(中间表) 可以查询、可以增删改
- /// 2、ManyToOne/ManyToMany外部表/PgArrayToMany 只可以查询,不支持增删改(会被忽略)
- ///
- [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
- public class AggregateRootBoundaryAttribute : Attribute
- {
- public string Name { get; set; }
- ///
- /// 边界是否终止
- ///
- public bool Break { get; set; }
- ///
- /// 边界是否终止向下探测
- ///
- public bool BreakThen { get; set; }
-
- public AggregateRootBoundaryAttribute(string name)
- {
- this.Name = name;
- }
- public AggregateRootBoundaryAttribute()
- {
- }
- }
-}
diff --git a/FreeSql.DbContext/AggregateRootRepository/AggregateRootModel.cs b/FreeSql.DbContext/AggregateRootRepository/AggregateRootModel.cs
deleted file mode 100644
index 7bff61bd..00000000
--- a/FreeSql.DbContext/AggregateRootRepository/AggregateRootModel.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace FreeSql.Internal.Model
-{
-
- public class AggregateRootTrackingChangeInfo
- {
-
- public List> InsertLog { get; } = new List>();
-
- public List>> UpdateLog { get; } = new List>>();
-
- public List> DeleteLog { get; } = new List>();
-
- }
-}
\ No newline at end of file
diff --git a/FreeSql.DbContext/AggregateRootRepository/AggregateRootRepository.cs b/FreeSql.DbContext/AggregateRootRepository/AggregateRootRepository.cs
deleted file mode 100644
index ed043f80..00000000
--- a/FreeSql.DbContext/AggregateRootRepository/AggregateRootRepository.cs
+++ /dev/null
@@ -1,261 +0,0 @@
-using FreeSql.Extensions.EntityUtil;
-using FreeSql.Internal.Model;
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using System.Linq.Expressions;
-
-namespace FreeSql
-{
- public interface IAggregateRootRepository: IBaseRepository where TEntity : class
- {
- IBaseRepository ChangeBoundary(string name);
- }
-
- public partial class AggregateRootRepository : IAggregateRootRepository where TEntity : class
- {
- readonly IBaseRepository _repository;
- public AggregateRootRepository(IFreeSql fsql)
- {
- if (fsql == null) throw new ArgumentNullException(nameof(fsql));
- _repository = fsql.GetRepository();
- _repository.DbContextOptions.EnableCascadeSave = false;
- }
- public AggregateRootRepository(IFreeSql fsql, UnitOfWorkManager uowManager) : this(uowManager?.Orm ?? fsql)
- {
- uowManager?.Binding(_repository);
- }
- public void Dispose()
- {
- DisposeChildRepositorys();
- _repository.FlushState();
- _repository.Dispose();
- FlushState();
- }
-
- string _boundaryName = "";
- public IBaseRepository ChangeBoundary(string name)
- {
- DisposeChildRepositorys();
- _repository.FlushState();
- FlushState();
- _boundaryName = string.Concat(name).Trim();
- return this;
- }
-
- public IFreeSql Orm => _repository.Orm;
- public IUnitOfWork UnitOfWork { get => _repository.UnitOfWork; set => _repository.UnitOfWork = value; }
- public DbContextOptions DbContextOptions
- {
- get => _repository.DbContextOptions;
- set
- {
- if (value == null) throw new ArgumentNullException(nameof(DbContextOptions));
- _repository.DbContextOptions = value;
- _repository.DbContextOptions.EnableCascadeSave = false;
- }
- }
- public void AsType(Type entityType) => _repository.AsType(entityType);
- Func _asTableRule;
- public void AsTable(Func rule)
- {
- _repository.AsTable(rule);
- _asTableRule = rule;
- }
- public Type EntityType => _repository.EntityType;
- public IDataFilter DataFilter => _repository.DataFilter;
-
- public void Attach(TEntity entity)
- {
- var state = CreateEntityState(entity);
- if (_states.ContainsKey(state.Key)) _states[state.Key] = state;
- else _states.Add(state.Key, state);
- }
- public void Attach(IEnumerable entity)
- {
- foreach (var item in entity)
- Attach(item);
- }
- public IBaseRepository AttachOnlyPrimary(TEntity data) => _repository.AttachOnlyPrimary(data);
- public Dictionary CompareState(TEntity newdata)
- {
- if (newdata == null) return null;
- var _table = Orm.CodeFirst.GetTableByEntity(EntityType);
- if (_table.Primarys.Any() == false) throw new Exception(DbContextStrings.Incomparable_EntityHasNo_PrimaryKey(Orm.GetEntityString(EntityType, newdata)));
- var key = Orm.GetEntityKeyString(EntityType, newdata, false);
- if (string.IsNullOrEmpty(key)) throw new Exception(DbContextStrings.Incomparable_PrimaryKey_NotSet(Orm.GetEntityString(EntityType, newdata)));
- if (_states.TryGetValue(key, out var oldState) == false || oldState == null) throw new Exception($"不可对比,数据未被跟踪:{Orm.GetEntityString(EntityType, newdata)}");
- AggregateRootTrackingChangeInfo tracking = new AggregateRootTrackingChangeInfo();
- AggregateRootUtils.CompareEntityValue(_boundaryName, Orm, EntityType, oldState, newdata, null, tracking);
- return new Dictionary
- {
- ["Insert"] = tracking.InsertLog.Select(a => new object[] { a.Item1, a.Item2 }).ToArray(),
- ["Delete"] = tracking.DeleteLog.Select(a => new object[] { a.Item1, a.Item2 }).ToArray(),
- ["Update"] = tracking.UpdateLog.Select(a => new object[] { a.Item1, a.Item2, a.Item3, a.Item4 }).ToArray(),
- };
- }
- public void FlushState()
- {
- DisposeChildRepositorys();
- _repository.FlushState();
- _states.Clear();
- }
-
- public IUpdate UpdateDiy => _repository.UpdateDiy;
- public ISelect Where(Expression> exp) => Select.Where(exp);
- public ISelect WhereIf(bool condition, Expression> exp) => Select.WhereIf(condition, exp);
-
- readonly Dictionary> _childRepositorys = new Dictionary>();
- IBaseRepository