mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-17 19:43:21 +08:00
- 移除 未发布的功能 FreeSqlBuilder.UseSeedData
This commit is contained in:
parent
6434be8727
commit
153c7915c3
@ -68,22 +68,6 @@ namespace base_entity
|
||||
//.UseConnectionString(FreeSql.DataType.OdbcDameng, "Driver={DM8 ODBC DRIVER};Server=127.0.0.1:5236;Persist Security Info=False;Trusted_Connection=Yes;UID=USER1;PWD=123456789")
|
||||
|
||||
.UseMonitorCommand(cmd => Console.Write(cmd.CommandText))
|
||||
.UseSeedData(sd => sd
|
||||
.Apply(new[]
|
||||
{
|
||||
new Products { Id = 1, title = "product-1" },
|
||||
new Products { Id = 2, title = "product-2" },
|
||||
new Products { Id = 3, title = "product-3" },
|
||||
new Products { Id = 4, title = "product-4" }
|
||||
})
|
||||
.Apply(new[]
|
||||
{
|
||||
new S_SysConfig<TestConfig> { Name = "testkey11", Config = new TestConfig { clicks = 11, title = "testtitle11" } },
|
||||
new S_SysConfig<TestConfig> { Name = "testkey22", Config = new TestConfig { clicks = 22, title = "testtitle22" } },
|
||||
new S_SysConfig<TestConfig> { Name = "testkey33", Config = new TestConfig { clicks = 33, title = "testtitle33" } }
|
||||
})
|
||||
)
|
||||
|
||||
.UseLazyLoading(true)
|
||||
.Build();
|
||||
BaseEntity.Initialization(fsql);
|
||||
|
@ -222,6 +222,15 @@
|
||||
</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>
|
||||
|
@ -740,14 +740,6 @@
|
||||
<param name="convertType"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.FreeSqlBuilder.UseSeedData(System.Action{FreeSql.FreeSqlBuilder.SeedDataBuilder})">
|
||||
<summary>
|
||||
CodeFirst 初始化种子数据<para></para>
|
||||
表数据为空时,创建设定的种子数据
|
||||
</summary>
|
||||
<param name="sd"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.FreeSqlBuilder.UseSyncStructureToLower(System.Boolean)">
|
||||
<summary>
|
||||
转小写同步结构
|
||||
|
@ -303,71 +303,9 @@ namespace FreeSql
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//SeedData
|
||||
if (_seedData != null && _seedData._data.Any())
|
||||
{
|
||||
ret.Aop.SyncStructureAfter += new EventHandler<Aop.SyncStructureAfterEventArgs>((s, e) =>
|
||||
{
|
||||
if (_seedData._data.Any() == false) return;
|
||||
foreach (var et in e.EntityTypes)
|
||||
{
|
||||
if (_seedData._data.TryGetValue(et, out var sd) == false) continue;
|
||||
if (sd.Any() == false) continue;
|
||||
if (ret.Select<object>().AsType(et).Any()) continue;
|
||||
ret.Insert<object>()
|
||||
.AsType(et)
|
||||
.NoneParameter()
|
||||
.InsertIdentity()
|
||||
.AppendData(sd.ToArray())
|
||||
.ExecuteAffrows();
|
||||
_seedData._data.TryRemove(et, out var old);
|
||||
}
|
||||
});
|
||||
|
||||
foreach (var sd in _seedData._data)
|
||||
{
|
||||
ret.CodeFirst.SyncStructure(sd.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public class SeedDataBuilder
|
||||
{
|
||||
internal ConcurrentDictionary<Type, List<object>> _data = new ConcurrentDictionary<Type, List<object>>();
|
||||
public SeedDataBuilder Apply<T>(T data) where T : class
|
||||
{
|
||||
if (_data.TryGetValue(typeof(T), out var ds) == false)
|
||||
_data.TryAdd(typeof(T), ds = new List<object>());
|
||||
ds.Add(data);
|
||||
return this;
|
||||
}
|
||||
public SeedDataBuilder Apply<T>(T[] data) where T : class
|
||||
{
|
||||
return this.Apply(data as IEnumerable<T>);
|
||||
}
|
||||
public SeedDataBuilder Apply<T>(IEnumerable<T> data) where T : class
|
||||
{
|
||||
foreach (var d in data) this.Apply(d);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
SeedDataBuilder _seedData;
|
||||
|
||||
/// <summary>
|
||||
/// CodeFirst 初始化种子数据<para></para>
|
||||
/// 表数据为空时,创建设定的种子数据
|
||||
/// </summary>
|
||||
/// <param name="sd"></param>
|
||||
/// <returns></returns>
|
||||
public FreeSqlBuilder UseSeedData(Action<SeedDataBuilder> sd)
|
||||
{
|
||||
_seedData = new SeedDataBuilder();
|
||||
sd?.Invoke(_seedData);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user