Replies: 3 comments 4 replies
-
简单说一下之前群里提到的疑惑: IFreeSql freeSql = new FreeSqlBuilder()
.UseConnectionString(DataType.Sqlite, "Data Source=:memory:;")
.UseAutoSyncStructure(true)
.Build();
freeSql.CodeFirst.SyncStructure(typeof(BizOrder), typeof(SysUser));
var tableRef = freeSql.CodeFirst.GetTableByEntity(typeof(BizOrder)).GetTableRef(nameof(BizOrder.CreatedUser), false);
tableRef.Dump();
//var tableRef1 = freeSql.CodeFirst.GetTableByEntity(typeof(SysUser)).GetTableRef(nameof(SysUser.CreatedOrders), false);
//tableRef1.Dump();
public class BizOrder
{
public Guid Id { get; set; }
public string Code { get; set; }
public DateTime? CreatedAt { get; set; }
public Guid? CreatedUserId { get; set; }
[Navigate(nameof(CreatedUserId))]
public SysUser CreatedUser { get; set; }
public DateTime? ModifiedAt { get; set; }
public Guid? ModifiedUserId { get; set; }
[Navigate(nameof(ModifiedUserId))]
public SysUser ModifiedUser { get; set; }
}
public class SysUser
{
public Guid Id { get; set; }
public string Code { get; set; }
public string Name { get; set; }
// 正常应该不会在参数表配置这种导航关系
//[Navigate(nameof(BizOrder.CreatedUserId))]
//public List<BizOrder> CreatedOrders { get; set; }
//
//[Navigate(nameof(BizOrder.ModifiedUserId))]
//public List<BizOrder> ModifiedOrders { get; set; }
} 测试发现默认情况下 |
Beta Was this translation helpful? Give feedback.
-
AggregateRootBoundary 需要调用 arrRepo.ChangeBoundary(); 太麻烦 |
Beta Was this translation helpful? Give feedback.
-
按照标准的DDD严格定义来说,凡是聚合根下的实体属性,以及这个实体属性中包含关联的实体,应该均属于领域边界内的,有着共同的生命周期,如果这样界定的话,其实导航属性作用就不大了,有没有导航属性,都要统一的增删改。 |
Beta Was this translation helpful? Give feedback.
-
我的想法是利用聚合根的特点,做这个功能不知道行不行的通。主要看实用性,会不会变成鸡肋,以及我没考虑到的情况。如果你有想法,欢迎留言~~~谢谢!!
FreeSql.Repository 定义了 IBaseRepository 仓储接口,实现了单表的通用仓储对象,支持了级联保存、级联删除功能,使用时需要人工自己判断何时开启、何时使用。
AggregateRootRepository 是 IBaseRepository 一种新的尝试实现,它将自动处理 OneToOne/OneToMany 导航属性,以及 ManyToMany 中间表的级联添加、级联更新、级联删除、级联查询(查询时自动 Include/IncludeMany 它们)。
详细的机制与说明:聚合根(实验室)
Beta Was this translation helpful? Give feedback.
All reactions