mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
add ToTreeList tests #268
This commit is contained in:
parent
f9566af7d1
commit
4e4240ff7a
@ -43,7 +43,7 @@ namespace FreeSql
|
||||
if (_optionsPriv == null)
|
||||
{
|
||||
_optionsPriv = new DbContextOptions();
|
||||
if (FreeSqlDbContextExtensions._dicSetDbContextOptions.TryGetValue(Orm, out var opt))
|
||||
if (FreeSqlDbContextExtensions._dicSetDbContextOptions.TryGetValue(Orm.Ado.Identifier, out var opt))
|
||||
{
|
||||
_optionsPriv.EnableAddOrUpdateNavigateList = opt.EnableAddOrUpdateNavigateList;
|
||||
_optionsPriv.OnEntityChange = opt.OnEntityChange;
|
||||
|
@ -35,10 +35,10 @@ public static class FreeSqlDbContextExtensions
|
||||
public static IFreeSql SetDbContextOptions(this IFreeSql that, Action<DbContextOptions> options)
|
||||
{
|
||||
if (options == null) return that;
|
||||
var cfg = _dicSetDbContextOptions.GetOrAdd(that, t => new DbContextOptions());
|
||||
var cfg = _dicSetDbContextOptions.GetOrAdd(that.Ado.Identifier, t => new DbContextOptions());
|
||||
options(cfg);
|
||||
_dicSetDbContextOptions.AddOrUpdate(that, cfg, (t, o) => cfg);
|
||||
_dicSetDbContextOptions.AddOrUpdate(that.Ado.Identifier, cfg, (t, o) => cfg);
|
||||
return that;
|
||||
}
|
||||
internal static ConcurrentDictionary<IFreeSql, DbContextOptions> _dicSetDbContextOptions = new ConcurrentDictionary<IFreeSql, DbContextOptions>();
|
||||
internal static ConcurrentDictionary<Guid, DbContextOptions> _dicSetDbContextOptions = new ConcurrentDictionary<Guid, DbContextOptions>();
|
||||
}
|
@ -121,13 +121,6 @@
|
||||
清空状态数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.DbSet`1.RemoveAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
|
||||
<summary>
|
||||
根据 lambda 条件删除数据
|
||||
</summary>
|
||||
<param name="predicate"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.DbSet`1.Add(`0)">
|
||||
<summary>
|
||||
添加
|
||||
@ -222,15 +215,6 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
||||
<summary>
|
||||
批量注入 Repository,可以参考代码自行调整
|
||||
</summary>
|
||||
<param name="services"></param>
|
||||
<param name="globalDataFilter"></param>
|
||||
<param name="assemblies"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="P:FreeSql.IBaseRepository.Orm">
|
||||
<summary>
|
||||
注意:IFreeSql 属于顶级对象,事务无法自动传递。<para></para>
|
||||
|
@ -148,7 +148,7 @@ namespace FreeSql.Tests
|
||||
|
||||
//支持 1对多 级联保存
|
||||
|
||||
using (var ctx = new FreeContext(g.sqlite))
|
||||
using (var ctx = g.sqlite.CreateDbContext())
|
||||
{
|
||||
|
||||
var tags = ctx.Set<Tag>().Select.IncludeMany(a => a.Tags).ToList();
|
||||
@ -177,7 +177,7 @@ namespace FreeSql.Tests
|
||||
{
|
||||
//查询 1对多,再级联保存
|
||||
|
||||
using (var ctx = new FreeContext(g.sqlite))
|
||||
using (var ctx = g.sqlite.CreateDbContext())
|
||||
{
|
||||
|
||||
var tag = ctx.Set<Tag>().Select.First();
|
||||
|
@ -1848,5 +1848,90 @@ WHERE ((b.`IsFinished` OR a.`TaskType` = 3) AND b.`EnabledMark` = 1)", groupsql1
|
||||
orm.Select<ToUpd1Pk>().ForUpdate(true).Limit(1).ToList();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeList()
|
||||
{
|
||||
var fsql = g.mysql;
|
||||
fsql.Delete<BaseDistrict>().Where("1=1").ExecuteAffrows();
|
||||
var repo = fsql.GetRepository<VM_District_Child>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.DbContextOptions.NoneParameter = true;
|
||||
repo.Insert(new VM_District_Child
|
||||
{
|
||||
Code = "100000",
|
||||
Name = "中国",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child
|
||||
{
|
||||
Code = "110000",
|
||||
Name = "北京市",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child{ Code="110100", Name = "北京市" },
|
||||
new VM_District_Child{ Code="110101", Name = "东城区" },
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
var t1 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t1);
|
||||
Assert.Equal("110101", t1[0].Code);
|
||||
Assert.NotNull(t1[0].Parent);
|
||||
Assert.Equal("110000", t1[0].Parent.Code);
|
||||
|
||||
var t2 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.InnerJoin(a => a.Parent.ParentCode == a.Parent.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t2);
|
||||
Assert.Equal("110101", t2[0].Code);
|
||||
Assert.NotNull(t2[0].Parent);
|
||||
Assert.Equal("110000", t2[0].Parent.Code);
|
||||
Assert.NotNull(t2[0].Parent.Parent);
|
||||
Assert.Equal("100000", t2[0].Parent.Parent.Code);
|
||||
|
||||
var t3 = fsql.Select<VM_District_Child>().ToTreeList();
|
||||
Assert.Single(t3);
|
||||
Assert.Equal("100000", t3[0].Code);
|
||||
Assert.Single(t3[0].Childs);
|
||||
Assert.Equal("110000", t3[0].Childs[0].Code);
|
||||
Assert.Equal(2, t3[0].Childs[0].Childs.Count);
|
||||
Assert.Equal("110100", t3[0].Childs[0].Childs[0].Code);
|
||||
Assert.Equal("110101", t3[0].Childs[0].Childs[1].Code);
|
||||
}
|
||||
|
||||
[Table(Name = "D_District")]
|
||||
public class BaseDistrict
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public virtual string ParentCode { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Child : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<VM_District_Child> Childs { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Parent : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public VM_District_Parent Parent { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1698,5 +1698,90 @@ WHERE (((to_char(a.""ID"")) in (SELECT b.""TITLE""
|
||||
orm.Select<ToUpd1Pk>().ForUpdate(true).Limit(1).ToList();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeList()
|
||||
{
|
||||
var fsql = g.dameng;
|
||||
fsql.Delete<BaseDistrict>().Where("1=1").ExecuteAffrows();
|
||||
var repo = fsql.GetRepository<VM_District_Child>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.DbContextOptions.NoneParameter = true;
|
||||
repo.Insert(new VM_District_Child
|
||||
{
|
||||
Code = "100000",
|
||||
Name = "中国",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child
|
||||
{
|
||||
Code = "110000",
|
||||
Name = "北京市",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child{ Code="110100", Name = "北京市" },
|
||||
new VM_District_Child{ Code="110101", Name = "东城区" },
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
var t1 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t1);
|
||||
Assert.Equal("110101", t1[0].Code);
|
||||
Assert.NotNull(t1[0].Parent);
|
||||
Assert.Equal("110000", t1[0].Parent.Code);
|
||||
|
||||
var t2 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.InnerJoin(a => a.Parent.ParentCode == a.Parent.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t2);
|
||||
Assert.Equal("110101", t2[0].Code);
|
||||
Assert.NotNull(t2[0].Parent);
|
||||
Assert.Equal("110000", t2[0].Parent.Code);
|
||||
Assert.NotNull(t2[0].Parent.Parent);
|
||||
Assert.Equal("100000", t2[0].Parent.Parent.Code);
|
||||
|
||||
var t3 = fsql.Select<VM_District_Child>().ToTreeList();
|
||||
Assert.Single(t3);
|
||||
Assert.Equal("100000", t3[0].Code);
|
||||
Assert.Single(t3[0].Childs);
|
||||
Assert.Equal("110000", t3[0].Childs[0].Code);
|
||||
Assert.Equal(2, t3[0].Childs[0].Childs.Count);
|
||||
Assert.Equal("110100", t3[0].Childs[0].Childs[0].Code);
|
||||
Assert.Equal("110101", t3[0].Childs[0].Childs[1].Code);
|
||||
}
|
||||
|
||||
[Table(Name = "D_District")]
|
||||
public class BaseDistrict
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public virtual string ParentCode { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Child : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<VM_District_Child> Childs { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Parent : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public VM_District_Parent Parent { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1510,5 +1510,90 @@ WHERE (((cast(a.[Id] as nvarchar)) in (SELECT b.[Title]
|
||||
orm.Select<ToUpd1Pk>().ForUpdate(true).Limit(1).ToList();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeList()
|
||||
{
|
||||
var fsql = g.odbc;
|
||||
fsql.Delete<BaseDistrict>().Where("1=1").ExecuteAffrows();
|
||||
var repo = fsql.GetRepository<VM_District_Child>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.DbContextOptions.NoneParameter = true;
|
||||
repo.Insert(new VM_District_Child
|
||||
{
|
||||
Code = "100000",
|
||||
Name = "中国",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child
|
||||
{
|
||||
Code = "110000",
|
||||
Name = "北京市",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child{ Code="110100", Name = "北京市" },
|
||||
new VM_District_Child{ Code="110101", Name = "东城区" },
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
var t1 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t1);
|
||||
Assert.Equal("110101", t1[0].Code);
|
||||
Assert.NotNull(t1[0].Parent);
|
||||
Assert.Equal("110000", t1[0].Parent.Code);
|
||||
|
||||
var t2 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.InnerJoin(a => a.Parent.ParentCode == a.Parent.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t2);
|
||||
Assert.Equal("110101", t2[0].Code);
|
||||
Assert.NotNull(t2[0].Parent);
|
||||
Assert.Equal("110000", t2[0].Parent.Code);
|
||||
Assert.NotNull(t2[0].Parent.Parent);
|
||||
Assert.Equal("100000", t2[0].Parent.Parent.Code);
|
||||
|
||||
var t3 = fsql.Select<VM_District_Child>().ToTreeList();
|
||||
Assert.Single(t3);
|
||||
Assert.Equal("100000", t3[0].Code);
|
||||
Assert.Single(t3[0].Childs);
|
||||
Assert.Equal("110000", t3[0].Childs[0].Code);
|
||||
Assert.Equal(2, t3[0].Childs[0].Childs.Count);
|
||||
Assert.Equal("110100", t3[0].Childs[0].Childs[0].Code);
|
||||
Assert.Equal("110101", t3[0].Childs[0].Childs[1].Code);
|
||||
}
|
||||
|
||||
[Table(Name = "D_District")]
|
||||
public class BaseDistrict
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public virtual string ParentCode { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Child : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<VM_District_Child> Childs { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Parent : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public VM_District_Parent Parent { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1859,5 +1859,90 @@ WHERE ((b.`IsFinished` OR a.`TaskType` = 3) AND b.`EnabledMark` = 1)", groupsql1
|
||||
orm.Select<ToUpd1Pk>().ForUpdate(true).Limit(1).ToList();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeList()
|
||||
{
|
||||
var fsql = g.mysql;
|
||||
fsql.Delete<BaseDistrict>().Where("1=1").ExecuteAffrows();
|
||||
var repo = fsql.GetRepository<VM_District_Child>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.DbContextOptions.NoneParameter = true;
|
||||
repo.Insert(new VM_District_Child
|
||||
{
|
||||
Code = "100000",
|
||||
Name = "中国",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child
|
||||
{
|
||||
Code = "110000",
|
||||
Name = "北京市",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child{ Code="110100", Name = "北京市" },
|
||||
new VM_District_Child{ Code="110101", Name = "东城区" },
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
var t1 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t1);
|
||||
Assert.Equal("110101", t1[0].Code);
|
||||
Assert.NotNull(t1[0].Parent);
|
||||
Assert.Equal("110000", t1[0].Parent.Code);
|
||||
|
||||
var t2 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.InnerJoin(a => a.Parent.ParentCode == a.Parent.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t2);
|
||||
Assert.Equal("110101", t2[0].Code);
|
||||
Assert.NotNull(t2[0].Parent);
|
||||
Assert.Equal("110000", t2[0].Parent.Code);
|
||||
Assert.NotNull(t2[0].Parent.Parent);
|
||||
Assert.Equal("100000", t2[0].Parent.Parent.Code);
|
||||
|
||||
var t3 = fsql.Select<VM_District_Child>().ToTreeList();
|
||||
Assert.Single(t3);
|
||||
Assert.Equal("100000", t3[0].Code);
|
||||
Assert.Single(t3[0].Childs);
|
||||
Assert.Equal("110000", t3[0].Childs[0].Code);
|
||||
Assert.Equal(2, t3[0].Childs[0].Childs.Count);
|
||||
Assert.Equal("110100", t3[0].Childs[0].Childs[0].Code);
|
||||
Assert.Equal("110101", t3[0].Childs[0].Childs[1].Code);
|
||||
}
|
||||
|
||||
[Table(Name = "D_District")]
|
||||
public class BaseDistrict
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public virtual string ParentCode { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Child : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<VM_District_Child> Childs { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Parent : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public VM_District_Parent Parent { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1699,5 +1699,90 @@ WHERE (((to_char(a.""ID"")) in (SELECT b.""TITLE""
|
||||
orm.Select<ToUpd1Pk>().ForUpdate(true).Limit(1).ToList();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeList()
|
||||
{
|
||||
var fsql = g.oracle;
|
||||
fsql.Delete<BaseDistrict>().Where("1=1").ExecuteAffrows();
|
||||
var repo = fsql.GetRepository<VM_District_Child>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.DbContextOptions.NoneParameter = true;
|
||||
repo.Insert(new VM_District_Child
|
||||
{
|
||||
Code = "100000",
|
||||
Name = "中国",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child
|
||||
{
|
||||
Code = "110000",
|
||||
Name = "北京市",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child{ Code="110100", Name = "北京市" },
|
||||
new VM_District_Child{ Code="110101", Name = "东城区" },
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
var t1 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t1);
|
||||
Assert.Equal("110101", t1[0].Code);
|
||||
Assert.NotNull(t1[0].Parent);
|
||||
Assert.Equal("110000", t1[0].Parent.Code);
|
||||
|
||||
var t2 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.InnerJoin(a => a.Parent.ParentCode == a.Parent.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t2);
|
||||
Assert.Equal("110101", t2[0].Code);
|
||||
Assert.NotNull(t2[0].Parent);
|
||||
Assert.Equal("110000", t2[0].Parent.Code);
|
||||
Assert.NotNull(t2[0].Parent.Parent);
|
||||
Assert.Equal("100000", t2[0].Parent.Parent.Code);
|
||||
|
||||
var t3 = fsql.Select<VM_District_Child>().ToTreeList();
|
||||
Assert.Single(t3);
|
||||
Assert.Equal("100000", t3[0].Code);
|
||||
Assert.Single(t3[0].Childs);
|
||||
Assert.Equal("110000", t3[0].Childs[0].Code);
|
||||
Assert.Equal(2, t3[0].Childs[0].Childs.Count);
|
||||
Assert.Equal("110100", t3[0].Childs[0].Childs[0].Code);
|
||||
Assert.Equal("110101", t3[0].Childs[0].Childs[1].Code);
|
||||
}
|
||||
|
||||
[Table(Name = "D_District")]
|
||||
public class BaseDistrict
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public virtual string ParentCode { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Child : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<VM_District_Child> Childs { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Parent : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public VM_District_Parent Parent { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1758,5 +1758,90 @@ WHERE ((((a.""id"")::varchar) in (SELECT b.""title""
|
||||
orm.Select<ToUpd1Pk>().ForUpdate(true).Limit(1).ToList();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeList()
|
||||
{
|
||||
var fsql = g.pgsql;
|
||||
fsql.Delete<BaseDistrict>().Where("1=1").ExecuteAffrows();
|
||||
var repo = fsql.GetRepository<VM_District_Child>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.DbContextOptions.NoneParameter = true;
|
||||
repo.Insert(new VM_District_Child
|
||||
{
|
||||
Code = "100000",
|
||||
Name = "中国",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child
|
||||
{
|
||||
Code = "110000",
|
||||
Name = "北京市",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child{ Code="110100", Name = "北京市" },
|
||||
new VM_District_Child{ Code="110101", Name = "东城区" },
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
var t1 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t1);
|
||||
Assert.Equal("110101", t1[0].Code);
|
||||
Assert.NotNull(t1[0].Parent);
|
||||
Assert.Equal("110000", t1[0].Parent.Code);
|
||||
|
||||
var t2 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.InnerJoin(a => a.Parent.ParentCode == a.Parent.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t2);
|
||||
Assert.Equal("110101", t2[0].Code);
|
||||
Assert.NotNull(t2[0].Parent);
|
||||
Assert.Equal("110000", t2[0].Parent.Code);
|
||||
Assert.NotNull(t2[0].Parent.Parent);
|
||||
Assert.Equal("100000", t2[0].Parent.Parent.Code);
|
||||
|
||||
var t3 = fsql.Select<VM_District_Child>().ToTreeList();
|
||||
Assert.Single(t3);
|
||||
Assert.Equal("100000", t3[0].Code);
|
||||
Assert.Single(t3[0].Childs);
|
||||
Assert.Equal("110000", t3[0].Childs[0].Code);
|
||||
Assert.Equal(2, t3[0].Childs[0].Childs.Count);
|
||||
Assert.Equal("110100", t3[0].Childs[0].Childs[0].Code);
|
||||
Assert.Equal("110101", t3[0].Childs[0].Childs[1].Code);
|
||||
}
|
||||
|
||||
[Table(Name = "D_District")]
|
||||
public class BaseDistrict
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public virtual string ParentCode { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Child : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<VM_District_Child> Childs { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Parent : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public VM_District_Parent Parent { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1649,5 +1649,90 @@ WHERE (((cast(a.[Id] as nvarchar)) in (SELECT b.[Title]
|
||||
orm.Select<ToUpd1Pk>().ForUpdate(true).Limit(1).ToList();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeList()
|
||||
{
|
||||
var fsql = g.sqlserver;
|
||||
fsql.Delete<BaseDistrict>().Where("1=1").ExecuteAffrows();
|
||||
var repo = fsql.GetRepository<VM_District_Child>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.DbContextOptions.NoneParameter = true;
|
||||
repo.Insert(new VM_District_Child
|
||||
{
|
||||
Code = "100000",
|
||||
Name = "中国",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child
|
||||
{
|
||||
Code = "110000",
|
||||
Name = "北京市",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child{ Code="110100", Name = "北京市" },
|
||||
new VM_District_Child{ Code="110101", Name = "东城区" },
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
var t1 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t1);
|
||||
Assert.Equal("110101", t1[0].Code);
|
||||
Assert.NotNull(t1[0].Parent);
|
||||
Assert.Equal("110000", t1[0].Parent.Code);
|
||||
|
||||
var t2 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.InnerJoin(a => a.Parent.ParentCode == a.Parent.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t2);
|
||||
Assert.Equal("110101", t2[0].Code);
|
||||
Assert.NotNull(t2[0].Parent);
|
||||
Assert.Equal("110000", t2[0].Parent.Code);
|
||||
Assert.NotNull(t2[0].Parent.Parent);
|
||||
Assert.Equal("100000", t2[0].Parent.Parent.Code);
|
||||
|
||||
var t3 = fsql.Select<VM_District_Child>().ToTreeList();
|
||||
Assert.Single(t3);
|
||||
Assert.Equal("100000", t3[0].Code);
|
||||
Assert.Single(t3[0].Childs);
|
||||
Assert.Equal("110000", t3[0].Childs[0].Code);
|
||||
Assert.Equal(2, t3[0].Childs[0].Childs.Count);
|
||||
Assert.Equal("110100", t3[0].Childs[0].Childs[0].Code);
|
||||
Assert.Equal("110101", t3[0].Childs[0].Childs[1].Code);
|
||||
}
|
||||
|
||||
[Table(Name = "D_District")]
|
||||
public class BaseDistrict
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public virtual string ParentCode { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Child : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<VM_District_Child> Childs { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Parent : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public VM_District_Parent Parent { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1511,5 +1511,90 @@ WHERE (((cstr(a.[Id])) in (SELECT b.[Title]
|
||||
orm.Select<ToUpd1Pk>().ForUpdate(true).Limit(1).ToList();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeList()
|
||||
{
|
||||
var fsql = g.msaccess;
|
||||
fsql.Delete<BaseDistrict>().Where("1=1").ExecuteAffrows();
|
||||
var repo = fsql.GetRepository<VM_District_Child>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.DbContextOptions.NoneParameter = true;
|
||||
repo.Insert(new VM_District_Child
|
||||
{
|
||||
Code = "100000",
|
||||
Name = "中国",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child
|
||||
{
|
||||
Code = "110000",
|
||||
Name = "北京市",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child{ Code="110100", Name = "北京市" },
|
||||
new VM_District_Child{ Code="110101", Name = "东城区" },
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
var t1 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t1);
|
||||
Assert.Equal("110101", t1[0].Code);
|
||||
Assert.NotNull(t1[0].Parent);
|
||||
Assert.Equal("110000", t1[0].Parent.Code);
|
||||
|
||||
var t2 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.InnerJoin(a => a.Parent.ParentCode == a.Parent.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t2);
|
||||
Assert.Equal("110101", t2[0].Code);
|
||||
Assert.NotNull(t2[0].Parent);
|
||||
Assert.Equal("110000", t2[0].Parent.Code);
|
||||
Assert.NotNull(t2[0].Parent.Parent);
|
||||
Assert.Equal("100000", t2[0].Parent.Parent.Code);
|
||||
|
||||
var t3 = fsql.Select<VM_District_Child>().ToTreeList();
|
||||
Assert.Single(t3);
|
||||
Assert.Equal("100000", t3[0].Code);
|
||||
Assert.Single(t3[0].Childs);
|
||||
Assert.Equal("110000", t3[0].Childs[0].Code);
|
||||
Assert.Equal(2, t3[0].Childs[0].Childs.Count);
|
||||
Assert.Equal("110100", t3[0].Childs[0].Childs[0].Code);
|
||||
Assert.Equal("110101", t3[0].Childs[0].Childs[1].Code);
|
||||
}
|
||||
|
||||
[Table(Name = "D_District")]
|
||||
public class BaseDistrict
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public virtual string ParentCode { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Child : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<VM_District_Child> Childs { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Parent : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public VM_District_Parent Parent { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1907,5 +1907,90 @@ WHERE ((b.`IsFinished` OR a.`TaskType` = 3) AND b.`EnabledMark` = 1)", groupsql1
|
||||
orm.Select<ToUpd1Pk>().ForUpdate(true).Limit(1).ToList();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeList()
|
||||
{
|
||||
var fsql = g.mysql;
|
||||
fsql.Delete<BaseDistrict>().Where("1=1").ExecuteAffrows();
|
||||
var repo = fsql.GetRepository<VM_District_Child>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.DbContextOptions.NoneParameter = true;
|
||||
repo.Insert(new VM_District_Child
|
||||
{
|
||||
Code = "100000",
|
||||
Name = "中国",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child
|
||||
{
|
||||
Code = "110000",
|
||||
Name = "北京市",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child{ Code="110100", Name = "北京市" },
|
||||
new VM_District_Child{ Code="110101", Name = "东城区" },
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
var t1 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t1);
|
||||
Assert.Equal("110101", t1[0].Code);
|
||||
Assert.NotNull(t1[0].Parent);
|
||||
Assert.Equal("110000", t1[0].Parent.Code);
|
||||
|
||||
var t2 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.InnerJoin(a => a.Parent.ParentCode == a.Parent.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t2);
|
||||
Assert.Equal("110101", t2[0].Code);
|
||||
Assert.NotNull(t2[0].Parent);
|
||||
Assert.Equal("110000", t2[0].Parent.Code);
|
||||
Assert.NotNull(t2[0].Parent.Parent);
|
||||
Assert.Equal("100000", t2[0].Parent.Parent.Code);
|
||||
|
||||
var t3 = fsql.Select<VM_District_Child>().ToTreeList();
|
||||
Assert.Single(t3);
|
||||
Assert.Equal("100000", t3[0].Code);
|
||||
Assert.Single(t3[0].Childs);
|
||||
Assert.Equal("110000", t3[0].Childs[0].Code);
|
||||
Assert.Equal(2, t3[0].Childs[0].Childs.Count);
|
||||
Assert.Equal("110100", t3[0].Childs[0].Childs[0].Code);
|
||||
Assert.Equal("110101", t3[0].Childs[0].Childs[1].Code);
|
||||
}
|
||||
|
||||
[Table(Name = "D_District")]
|
||||
public class BaseDistrict
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public virtual string ParentCode { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Child : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<VM_District_Child> Childs { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Parent : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public VM_District_Parent Parent { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1699,5 +1699,90 @@ WHERE (((to_char(a.""ID"")) in (SELECT b.""TITLE""
|
||||
orm.Select<ToUpd1Pk>().ForUpdate(true).Limit(1).ToList();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeList()
|
||||
{
|
||||
var fsql = g.oracle;
|
||||
fsql.Delete<BaseDistrict>().Where("1=1").ExecuteAffrows();
|
||||
var repo = fsql.GetRepository<VM_District_Child>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.DbContextOptions.NoneParameter = true;
|
||||
repo.Insert(new VM_District_Child
|
||||
{
|
||||
Code = "100000",
|
||||
Name = "中国",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child
|
||||
{
|
||||
Code = "110000",
|
||||
Name = "北京市",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child{ Code="110100", Name = "北京市" },
|
||||
new VM_District_Child{ Code="110101", Name = "东城区" },
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
var t1 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t1);
|
||||
Assert.Equal("110101", t1[0].Code);
|
||||
Assert.NotNull(t1[0].Parent);
|
||||
Assert.Equal("110000", t1[0].Parent.Code);
|
||||
|
||||
var t2 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.InnerJoin(a => a.Parent.ParentCode == a.Parent.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t2);
|
||||
Assert.Equal("110101", t2[0].Code);
|
||||
Assert.NotNull(t2[0].Parent);
|
||||
Assert.Equal("110000", t2[0].Parent.Code);
|
||||
Assert.NotNull(t2[0].Parent.Parent);
|
||||
Assert.Equal("100000", t2[0].Parent.Parent.Code);
|
||||
|
||||
var t3 = fsql.Select<VM_District_Child>().ToTreeList();
|
||||
Assert.Single(t3);
|
||||
Assert.Equal("100000", t3[0].Code);
|
||||
Assert.Single(t3[0].Childs);
|
||||
Assert.Equal("110000", t3[0].Childs[0].Code);
|
||||
Assert.Equal(2, t3[0].Childs[0].Childs.Count);
|
||||
Assert.Equal("110100", t3[0].Childs[0].Childs[0].Code);
|
||||
Assert.Equal("110101", t3[0].Childs[0].Childs[1].Code);
|
||||
}
|
||||
|
||||
[Table(Name = "D_District")]
|
||||
public class BaseDistrict
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public virtual string ParentCode { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Child : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<VM_District_Child> Childs { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Parent : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public VM_District_Parent Parent { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1775,5 +1775,89 @@ WHERE ((((a.""id"")::varchar) in (SELECT b.""title""
|
||||
orm.Select<ToUpd1Pk>().ForUpdate(true).Limit(1).ToList();
|
||||
});
|
||||
}
|
||||
[Fact]
|
||||
public void ToTreeList()
|
||||
{
|
||||
var fsql = g.pgsql;
|
||||
fsql.Delete<BaseDistrict>().Where("1=1").ExecuteAffrows();
|
||||
var repo = fsql.GetRepository<VM_District_Child>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.DbContextOptions.NoneParameter = true;
|
||||
repo.Insert(new VM_District_Child
|
||||
{
|
||||
Code = "100000",
|
||||
Name = "中国",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child
|
||||
{
|
||||
Code = "110000",
|
||||
Name = "北京市",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child{ Code="110100", Name = "北京市" },
|
||||
new VM_District_Child{ Code="110101", Name = "东城区" },
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
var t1 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t1);
|
||||
Assert.Equal("110101", t1[0].Code);
|
||||
Assert.NotNull(t1[0].Parent);
|
||||
Assert.Equal("110000", t1[0].Parent.Code);
|
||||
|
||||
var t2 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.InnerJoin(a => a.Parent.ParentCode == a.Parent.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t2);
|
||||
Assert.Equal("110101", t2[0].Code);
|
||||
Assert.NotNull(t2[0].Parent);
|
||||
Assert.Equal("110000", t2[0].Parent.Code);
|
||||
Assert.NotNull(t2[0].Parent.Parent);
|
||||
Assert.Equal("100000", t2[0].Parent.Parent.Code);
|
||||
|
||||
var t3 = fsql.Select<VM_District_Child>().ToTreeList();
|
||||
Assert.Single(t3);
|
||||
Assert.Equal("100000", t3[0].Code);
|
||||
Assert.Single(t3[0].Childs);
|
||||
Assert.Equal("110000", t3[0].Childs[0].Code);
|
||||
Assert.Equal(2, t3[0].Childs[0].Childs.Count);
|
||||
Assert.Equal("110100", t3[0].Childs[0].Childs[0].Code);
|
||||
Assert.Equal("110101", t3[0].Childs[0].Childs[1].Code);
|
||||
}
|
||||
|
||||
[Table(Name = "D_District")]
|
||||
public class BaseDistrict
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public virtual string ParentCode { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Child : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<VM_District_Child> Childs { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Parent : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public VM_District_Parent Parent { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1730,5 +1730,90 @@ WHERE (((cast(a.[Id] as nvarchar)) in (SELECT b.[Title]
|
||||
orm.Select<ToUpd1Pk>().ForUpdate(true).Limit(1).ToList();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeList()
|
||||
{
|
||||
var fsql = g.sqlserver;
|
||||
fsql.Delete<BaseDistrict>().Where("1=1").ExecuteAffrows();
|
||||
var repo = fsql.GetRepository<VM_District_Child>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.DbContextOptions.NoneParameter = true;
|
||||
repo.Insert(new VM_District_Child
|
||||
{
|
||||
Code = "100000",
|
||||
Name = "中国",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child
|
||||
{
|
||||
Code = "110000",
|
||||
Name = "北京市",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child{ Code="110100", Name = "北京市" },
|
||||
new VM_District_Child{ Code="110101", Name = "东城区" },
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
var t1 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t1);
|
||||
Assert.Equal("110101", t1[0].Code);
|
||||
Assert.NotNull(t1[0].Parent);
|
||||
Assert.Equal("110000", t1[0].Parent.Code);
|
||||
|
||||
var t2 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.InnerJoin(a => a.Parent.ParentCode == a.Parent.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t2);
|
||||
Assert.Equal("110101", t2[0].Code);
|
||||
Assert.NotNull(t2[0].Parent);
|
||||
Assert.Equal("110000", t2[0].Parent.Code);
|
||||
Assert.NotNull(t2[0].Parent.Parent);
|
||||
Assert.Equal("100000", t2[0].Parent.Parent.Code);
|
||||
|
||||
var t3 = fsql.Select<VM_District_Child>().ToTreeList();
|
||||
Assert.Single(t3);
|
||||
Assert.Equal("100000", t3[0].Code);
|
||||
Assert.Single(t3[0].Childs);
|
||||
Assert.Equal("110000", t3[0].Childs[0].Code);
|
||||
Assert.Equal(2, t3[0].Childs[0].Childs.Count);
|
||||
Assert.Equal("110100", t3[0].Childs[0].Childs[0].Code);
|
||||
Assert.Equal("110101", t3[0].Childs[0].Childs[1].Code);
|
||||
}
|
||||
|
||||
[Table(Name = "D_District")]
|
||||
public class BaseDistrict
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public virtual string ParentCode { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Child : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<VM_District_Child> Childs { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Parent : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public VM_District_Parent Parent { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1846,5 +1846,90 @@ WHERE (((cast(a.""Id"" as character)) in (SELECT b.""Title""
|
||||
orm.Select<ToUpd1Pk>().ForUpdate(true).Limit(1).ToList();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeList()
|
||||
{
|
||||
var fsql = g.sqlite;
|
||||
fsql.Delete<BaseDistrict>().Where("1=1").ExecuteAffrows();
|
||||
var repo = fsql.GetRepository<VM_District_Child>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.DbContextOptions.NoneParameter = true;
|
||||
repo.Insert(new VM_District_Child
|
||||
{
|
||||
Code = "100000",
|
||||
Name = "中国",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child
|
||||
{
|
||||
Code = "110000",
|
||||
Name = "北京市",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child{ Code="110100", Name = "北京市" },
|
||||
new VM_District_Child{ Code="110101", Name = "东城区" },
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
var t1 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t1);
|
||||
Assert.Equal("110101", t1[0].Code);
|
||||
Assert.NotNull(t1[0].Parent);
|
||||
Assert.Equal("110000", t1[0].Parent.Code);
|
||||
|
||||
var t2 = fsql.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.InnerJoin(a => a.Parent.ParentCode == a.Parent.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t2);
|
||||
Assert.Equal("110101", t2[0].Code);
|
||||
Assert.NotNull(t2[0].Parent);
|
||||
Assert.Equal("110000", t2[0].Parent.Code);
|
||||
Assert.NotNull(t2[0].Parent.Parent);
|
||||
Assert.Equal("100000", t2[0].Parent.Parent.Code);
|
||||
|
||||
var t3 = fsql.Select<VM_District_Child>().ToTreeList();
|
||||
Assert.Single(t3);
|
||||
Assert.Equal("100000", t3[0].Code);
|
||||
Assert.Single(t3[0].Childs);
|
||||
Assert.Equal("110000", t3[0].Childs[0].Code);
|
||||
Assert.Equal(2, t3[0].Childs[0].Childs.Count);
|
||||
Assert.Equal("110100", t3[0].Childs[0].Childs[0].Code);
|
||||
Assert.Equal("110101", t3[0].Childs[0].Childs[1].Code);
|
||||
}
|
||||
|
||||
[Table(Name = "D_District")]
|
||||
public class BaseDistrict
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public virtual string ParentCode { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Child : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<VM_District_Child> Childs { get; set; }
|
||||
}
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Parent : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public VM_District_Parent Parent { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,111 +0,0 @@
|
||||
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;
|
||||
using System.Threading;
|
||||
using System.Data.SqlClient;
|
||||
using kwlib;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace FreeSql.Tests
|
||||
{
|
||||
public class UnitTest4
|
||||
{
|
||||
[Fact]
|
||||
public void Test04()
|
||||
{
|
||||
g.sqlite.Delete<BaseDistrict>().Where("1=1").ExecuteAffrows();
|
||||
var repo = g.sqlite.GetRepository<VM_District_Child>();
|
||||
repo.DbContextOptions.EnableAddOrUpdateNavigateList = true;
|
||||
repo.DbContextOptions.NoneParameter = true;
|
||||
repo.Insert(new VM_District_Child
|
||||
{
|
||||
Code = "100000",
|
||||
Name = "中国",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child
|
||||
{
|
||||
Code = "110000",
|
||||
Name = "北京市",
|
||||
Childs = new List<VM_District_Child>(new[] {
|
||||
new VM_District_Child{ Code="110100", Name = "北京市" },
|
||||
new VM_District_Child{ Code="110101", Name = "东城区" },
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
var t1 = g.sqlite.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t1);
|
||||
Assert.Equal("110101", t1[0].Code);
|
||||
Assert.NotNull(t1[0].Parent);
|
||||
Assert.Equal("110000", t1[0].Parent.Code);
|
||||
|
||||
var t2 = g.sqlite.Select<VM_District_Parent>()
|
||||
.InnerJoin(a => a.ParentCode == a.Parent.Code)
|
||||
.InnerJoin(a => a.Parent.ParentCode == a.Parent.Parent.Code)
|
||||
.Where(a => a.Code == "110101")
|
||||
.ToList(true);
|
||||
Assert.Single(t2);
|
||||
Assert.Equal("110101", t2[0].Code);
|
||||
Assert.NotNull(t2[0].Parent);
|
||||
Assert.Equal("110000", t2[0].Parent.Code);
|
||||
Assert.NotNull(t2[0].Parent.Parent);
|
||||
Assert.Equal("100000", t2[0].Parent.Parent.Code);
|
||||
|
||||
var t3 = g.sqlite.Select<VM_District_Child>().ToTreeList();
|
||||
Assert.Single(t3);
|
||||
Assert.Equal("100000", t3[0].Code);
|
||||
Assert.Single(t3[0].Childs);
|
||||
Assert.Equal("110000", t3[0].Childs[0].Code);
|
||||
Assert.Equal(2, t3[0].Childs[0].Childs.Count);
|
||||
Assert.Equal("110100", t3[0].Childs[0].Childs[0].Code);
|
||||
Assert.Equal("110101", t3[0].Childs[0].Childs[1].Code);
|
||||
}
|
||||
|
||||
[Table(Name = "D_District")]
|
||||
public class BaseDistrict
|
||||
{
|
||||
[Column(IsPrimary = true, StringLength = 6)]
|
||||
public string Code { get; set; }
|
||||
|
||||
[Column(StringLength = 20, IsNullable = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Column(StringLength = 6)]
|
||||
public virtual string ParentCode { get; set; }
|
||||
}
|
||||
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Child : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public List<VM_District_Child> Childs { get; set; }
|
||||
}
|
||||
|
||||
[Table(Name = "D_District", DisableSyncStructure = true)]
|
||||
public class VM_District_Parent : BaseDistrict
|
||||
{
|
||||
public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; }
|
||||
|
||||
[Navigate(nameof(ParentCode))]
|
||||
public VM_District_Parent Parent { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -2119,6 +2119,11 @@
|
||||
UseSalve 时候的值
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.IAdo.Identifier">
|
||||
<summary>
|
||||
唯一标识
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.Transaction(System.Action)">
|
||||
<summary>
|
||||
开启事务(不支持异步),60秒未执行完成(可能)被其他线程事务自动提交
|
||||
@ -2276,137 +2281,6 @@
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteReaderAsync(System.Func{System.Data.Common.DbDataReader,System.Threading.Tasks.Task},System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
查询,若使用读写分离,查询【从库】条件cmdText.StartsWith("SELECT "),否则查询【主库】
|
||||
</summary>
|
||||
<param name="readerHander"></param>
|
||||
<param name="cmdType"></param>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteReaderAsync(System.Func{System.Data.Common.DbDataReader,System.Threading.Tasks.Task},System.String,System.Object)">
|
||||
<summary>
|
||||
查询,ExecuteReaderAsync(dr => {}, "select * from user where age > ?age", new { age = 25 })
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteArrayAsync(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
查询
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteArrayAsync(System.String,System.Object)">
|
||||
<summary>
|
||||
查询,ExecuteArrayAsync("select * from user where age > ?age", new { age = 25 })
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteDataSetAsync(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
查询
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteDataSetAsync(System.String,System.Object)">
|
||||
<summary>
|
||||
查询,ExecuteDataSetAsync("select * from user where age > ?age; select 2", new { age = 25 })
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteDataTableAsync(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
查询
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteDataTableAsync(System.String,System.Object)">
|
||||
<summary>
|
||||
查询,ExecuteDataTableAsync("select * from user where age > ?age", new { age = 25 })
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteNonQueryAsync(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
在【主库】执行
|
||||
</summary>
|
||||
<param name="cmdType"></param>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteNonQueryAsync(System.String,System.Object)">
|
||||
<summary>
|
||||
在【主库】执行,ExecuteNonQueryAsync("delete from user where age > ?age", new { age = 25 })
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteScalarAsync(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
在【主库】执行
|
||||
</summary>
|
||||
<param name="cmdType"></param>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.ExecuteScalarAsync(System.String,System.Object)">
|
||||
<summary>
|
||||
在【主库】执行,ExecuteScalarAsync("select 1 from user where age > ?age", new { age = 25 })
|
||||
</summary>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.QueryAsync``1(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
执行SQL返回对象集合,QueryAsync<User>("select * from user where age > ?age", new SqlParameter { ParameterName = "age", Value = 25 })
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<param name="cmdType"></param>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.QueryAsync``1(System.String,System.Object)">
|
||||
<summary>
|
||||
执行SQL返回对象集合,QueryAsync<User>("select * from user where age > ?age", new { age = 25 })
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.QueryAsync``2(System.Data.CommandType,System.String,System.Data.Common.DbParameter[])">
|
||||
<summary>
|
||||
执行SQL返回对象集合,Query<User>("select * from user where age > ?age; select * from address", new SqlParameter { ParameterName = "age", Value = 25 })
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="cmdType"></param>
|
||||
<param name="cmdText"></param>
|
||||
<param name="cmdParms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.IAdo.QueryAsync``2(System.String,System.Object)">
|
||||
<summary>
|
||||
执行SQL返回对象集合,Query<User>("select * from user where age > ?age; select * from address", new { age = 25 })
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="cmdText"></param>
|
||||
<param name="parms"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="E:FreeSql.IAop.ParseExpression">
|
||||
<summary>
|
||||
可自定义解析表达式
|
||||
@ -2927,12 +2801,6 @@
|
||||
<param name="timeout">超时</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Internal.ObjectPool.IObjectPool`1.GetAsync">
|
||||
<summary>
|
||||
获取资源
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.Internal.ObjectPool.IObjectPool`1.Return(FreeSql.Internal.ObjectPool.Object{`0},System.Boolean)">
|
||||
<summary>
|
||||
使用完毕后,归还资源
|
||||
@ -3003,12 +2871,6 @@
|
||||
</summary>
|
||||
<param name="obj">资源对象</param>
|
||||
</member>
|
||||
<member name="M:FreeSql.Internal.ObjectPool.IPolicy`1.OnGetAsync(FreeSql.Internal.ObjectPool.Object{`0})">
|
||||
<summary>
|
||||
从对象池获取对象成功的时候触发,通过该方法统计或初始化对象
|
||||
</summary>
|
||||
<param name="obj">资源对象</param>
|
||||
</member>
|
||||
<member name="M:FreeSql.Internal.ObjectPool.IPolicy`1.OnReturn(FreeSql.Internal.ObjectPool.Object{`0})">
|
||||
<summary>
|
||||
归还对象给对象池的时候触发
|
||||
@ -3641,4 +3503,167 @@
|
||||
</summary>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:System.Linq.Expressions.LambadaExpressionExtensions.Or``5(System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,``4,System.Boolean}},System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,``4,System.Boolean}})">
|
||||
<summary>
|
||||
使用 or 拼接两个 lambda 表达式
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:System.Linq.Expressions.LambadaExpressionExtensions.Or``5(System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,``4,System.Boolean}},System.Boolean,System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,``4,System.Boolean}})">
|
||||
<summary>
|
||||
使用 or 拼接两个 lambda 表达式
|
||||
</summary>
|
||||
<param name="exp1"></param>
|
||||
<param name="condition">true 时生效</param>
|
||||
<param name="exp2"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:System.Linq.Expressions.LambadaExpressionExtensions.Not``5(System.Linq.Expressions.Expression{System.Func{``0,``1,``2,``3,``4,System.Boolean}},System.Boolean)">
|
||||
<summary>
|
||||
将 lambda 表达式取反
|
||||
</summary>
|
||||
<param name="exp"></param>
|
||||
<param name="condition">true 时生效</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeUtil.NewMongodbId">
|
||||
<summary>
|
||||
生成类似Mongodb的ObjectId有序、不重复Guid
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Insert``1">
|
||||
<summary>
|
||||
插入数据
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Insert``1(``0)">
|
||||
<summary>
|
||||
插入数据,传入实体
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="source"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Insert``1(``0[])">
|
||||
<summary>
|
||||
插入数据,传入实体数组
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="source"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Insert``1(System.Collections.Generic.List{``0})">
|
||||
<summary>
|
||||
插入数据,传入实体集合
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="source"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Insert``1(System.Collections.Generic.IEnumerable{``0})">
|
||||
<summary>
|
||||
插入数据,传入实体集合
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="source"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Update``1">
|
||||
<summary>
|
||||
修改数据
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Update``1(System.Object)">
|
||||
<summary>
|
||||
修改数据,传入动态对象如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Select``1">
|
||||
<summary>
|
||||
查询数据
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Select``1(System.Object)">
|
||||
<summary>
|
||||
查询数据,传入动态对象如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Delete``1">
|
||||
<summary>
|
||||
删除数据
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Delete``1(System.Object)">
|
||||
<summary>
|
||||
删除数据,传入动态对象如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}
|
||||
</summary>
|
||||
<typeparam name="T1"></typeparam>
|
||||
<param name="dywhere">主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Transaction(System.Action)">
|
||||
<summary>
|
||||
开启事务(不支持异步),60秒未执行完成(可能)被其他线程事务自动提交
|
||||
</summary>
|
||||
<param name="handler">事务体 () => {}</param>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Transaction(System.TimeSpan,System.Action)">
|
||||
<summary>
|
||||
开启事务(不支持异步)
|
||||
</summary>
|
||||
<param name="timeout">超时,未执行完成(可能)被其他线程事务自动提交</param>
|
||||
<param name="handler">事务体 () => {}</param>
|
||||
</member>
|
||||
<member name="M:IFreeSql.Transaction(System.Data.IsolationLevel,System.TimeSpan,System.Action)">
|
||||
<summary>
|
||||
开启事务(不支持异步)
|
||||
</summary>
|
||||
<param name="isolationLevel"></param>
|
||||
<param name="handler">事务体 () => {}</param>
|
||||
<param name="timeout">超时,未执行完成(可能)被其他线程事务自动提交</param>
|
||||
</member>
|
||||
<member name="P:IFreeSql.Ado">
|
||||
<summary>
|
||||
数据库访问对象
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IFreeSql.Aop">
|
||||
<summary>
|
||||
所有拦截方法都在这里
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IFreeSql.CodeFirst">
|
||||
<summary>
|
||||
CodeFirst 模式开发相关方法
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IFreeSql.DbFirst">
|
||||
<summary>
|
||||
DbFirst 模式开发相关方法
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IFreeSql.GlobalFilter">
|
||||
<summary>
|
||||
全局过滤设置,可默认附加为 Select/Update/Delete 条件
|
||||
</summary>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
@ -32,6 +32,10 @@ namespace FreeSql
|
||||
/// UseSalve 时候的值
|
||||
/// </summary>
|
||||
string[] SlaveConnectionStrings { get; }
|
||||
/// <summary>
|
||||
/// 唯一标识
|
||||
/// </summary>
|
||||
Guid Identifier { get; }
|
||||
|
||||
#region 事务
|
||||
/// <summary>
|
||||
|
@ -26,6 +26,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
public DataType DataType { get; }
|
||||
public string ConnectionString { get; }
|
||||
public string[] SlaveConnectionStrings { get; }
|
||||
public Guid Identifier { get; }
|
||||
protected CommonUtils _util { get; set; }
|
||||
protected int slaveUnavailables = 0;
|
||||
private object slaveLock = new object();
|
||||
@ -36,6 +37,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
this.DataType = dataType;
|
||||
this.ConnectionString = connectionString;
|
||||
this.SlaveConnectionStrings = slaveConnectionStrings;
|
||||
this.Identifier = Guid.NewGuid();
|
||||
}
|
||||
|
||||
void LoggerException(IObjectPool<DbConnection> pool, PrepareCommandResult pc, Exception ex, DateTime dt, StringBuilder logtxt, bool isThrowException = true)
|
||||
|
@ -101,7 +101,7 @@ namespace FreeSql.Odbc.Default
|
||||
}
|
||||
finally
|
||||
{
|
||||
FreeSqlOdbcGlobalExtensions._dicOdbcAdater.TryRemove(this as IFreeSql, out var tryada);
|
||||
FreeSqlOdbcGlobalExtensions._dicOdbcAdater.TryRemove(Ado.Identifier, out var tryada);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -110,7 +110,7 @@ namespace FreeSql.Odbc.Default
|
||||
partial class FreeSqlOdbcGlobalExtensions
|
||||
{
|
||||
internal static OdbcAdapter DefaultOdbcAdapter = new OdbcAdapter();
|
||||
internal static ConcurrentDictionary<IFreeSql, OdbcAdapter> _dicOdbcAdater = new ConcurrentDictionary<IFreeSql, OdbcAdapter>();
|
||||
public static void SetOdbcAdapter(this IFreeSql that, OdbcAdapter adapter) => _dicOdbcAdater.AddOrUpdate(that, adapter, (fsql, old) => adapter);
|
||||
internal static OdbcAdapter GetOdbcAdapter(this IFreeSql that) => _dicOdbcAdater.TryGetValue(that, out var tryada) ? tryada : DefaultOdbcAdapter;
|
||||
internal static ConcurrentDictionary<Guid, OdbcAdapter> _dicOdbcAdater = new ConcurrentDictionary<Guid, OdbcAdapter>();
|
||||
public static void SetOdbcAdapter(this IFreeSql that, OdbcAdapter adapter) => _dicOdbcAdater.AddOrUpdate(that.Ado.Identifier, adapter, (fsql, old) => adapter);
|
||||
internal static OdbcAdapter GetOdbcAdapter(this IFreeSql that) => _dicOdbcAdater.TryGetValue(that.Ado.Identifier, out var tryada) ? tryada : DefaultOdbcAdapter;
|
||||
}
|
||||
|
@ -249,7 +249,7 @@ namespace FreeSql.SqlServer.Curd
|
||||
#endregion
|
||||
|
||||
public SqlServerSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) {
|
||||
if (FreeSqlSqlServerGlobalExtensions._dicSetGlobalSelectWithLock.TryGetValue(orm, out var tryval))
|
||||
if (FreeSqlSqlServerGlobalExtensions._dicSetGlobalSelectWithLock.TryGetValue(orm.Ado.Identifier, out var tryval))
|
||||
this.WithLock(tryval.Item1, tryval.Item2);
|
||||
}
|
||||
public override ISelect<T1, T2> From<T2>(Expression<Func<ISelectFromExpression<T1>, T2, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp); var ret = new SqlServerSelect<T1, T2>(_orm, _commonUtils, _commonExpression, null); SqlServerSelect<T1>.CopyData(this, ret, exp?.Parameters); return ret; }
|
||||
|
@ -39,10 +39,10 @@ public static partial class FreeSqlSqlServerGlobalExtensions
|
||||
public static IFreeSql SetGlobalSelectWithLock(this IFreeSql that, SqlServerLock lockType, Dictionary<Type, bool> rule)
|
||||
{
|
||||
var value = NaviteTuple.Create(lockType, rule);
|
||||
_dicSetGlobalSelectWithLock.AddOrUpdate(that, value, (_, __) => value);
|
||||
_dicSetGlobalSelectWithLock.AddOrUpdate(that.Ado.Identifier, value, (_, __) => value);
|
||||
return that;
|
||||
}
|
||||
internal static ConcurrentDictionary<IFreeSql, NaviteTuple<SqlServerLock, Dictionary<Type, bool>>> _dicSetGlobalSelectWithLock = new ConcurrentDictionary<IFreeSql, NaviteTuple<SqlServerLock, Dictionary<Type, bool>>>();
|
||||
internal static ConcurrentDictionary<Guid, NaviteTuple<SqlServerLock, Dictionary<Type, bool>>> _dicSetGlobalSelectWithLock = new ConcurrentDictionary<Guid, NaviteTuple<SqlServerLock, Dictionary<Type, bool>>>();
|
||||
|
||||
#region ExecuteSqlBulkCopy
|
||||
/// <summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user