From 153c7915c3c1583ac2ff5f5c50342126ecbd54bb Mon Sep 17 00:00:00 2001 From: 28810 <28810@YEXIANGQIN> Date: Fri, 3 Apr 2020 09:17:40 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E7=A7=BB=E9=99=A4=20=E6=9C=AA=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E7=9A=84=E5=8A=9F=E8=83=BD=20FreeSqlBuilder.UseSeedDa?= =?UTF-8?q?ta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Examples/base_entity/Program.cs | 16 ------- FreeSql.DbContext/FreeSql.DbContext.xml | 9 ++++ FreeSql/FreeSql.xml | 8 ---- FreeSql/FreeSqlBuilder.cs | 62 ------------------------- 4 files changed, 9 insertions(+), 86 deletions(-) diff --git a/Examples/base_entity/Program.cs b/Examples/base_entity/Program.cs index 9d762f82..0db13185 100644 --- a/Examples/base_entity/Program.cs +++ b/Examples/base_entity/Program.cs @@ -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 { Name = "testkey11", Config = new TestConfig { clicks = 11, title = "testtitle11" } }, - new S_SysConfig { Name = "testkey22", Config = new TestConfig { clicks = 22, title = "testtitle22" } }, - new S_SysConfig { Name = "testkey33", Config = new TestConfig { clicks = 33, title = "testtitle33" } } - }) - ) - .UseLazyLoading(true) .Build(); BaseEntity.Initialization(fsql); diff --git a/FreeSql.DbContext/FreeSql.DbContext.xml b/FreeSql.DbContext/FreeSql.DbContext.xml index 3cbd07b4..eacd506b 100644 --- a/FreeSql.DbContext/FreeSql.DbContext.xml +++ b/FreeSql.DbContext/FreeSql.DbContext.xml @@ -222,6 +222,15 @@ + + + 批量注入 Repository,可以参考代码自行调整 + + + + + + 注意:IFreeSql 属于顶级对象,事务无法自动传递。 diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml index 94b4980f..13c418f1 100644 --- a/FreeSql/FreeSql.xml +++ b/FreeSql/FreeSql.xml @@ -740,14 +740,6 @@ - - - CodeFirst 初始化种子数据 - 表数据为空时,创建设定的种子数据 - - - - 转小写同步结构 diff --git a/FreeSql/FreeSqlBuilder.cs b/FreeSql/FreeSqlBuilder.cs index 319bed75..b72283eb 100644 --- a/FreeSql/FreeSqlBuilder.cs +++ b/FreeSql/FreeSqlBuilder.cs @@ -303,71 +303,9 @@ namespace FreeSql } } }); - - //SeedData - if (_seedData != null && _seedData._data.Any()) - { - ret.Aop.SyncStructureAfter += new EventHandler((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().AsType(et).Any()) continue; - ret.Insert() - .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> _data = new ConcurrentDictionary>(); - public SeedDataBuilder Apply(T data) where T : class - { - if (_data.TryGetValue(typeof(T), out var ds) == false) - _data.TryAdd(typeof(T), ds = new List()); - ds.Add(data); - return this; - } - public SeedDataBuilder Apply(T[] data) where T : class - { - return this.Apply(data as IEnumerable); - } - public SeedDataBuilder Apply(IEnumerable data) where T : class - { - foreach (var d in data) this.Apply(d); - return this; - } - } - SeedDataBuilder _seedData; - - /// - /// CodeFirst 初始化种子数据 - /// 表数据为空时,创建设定的种子数据 - /// - /// - /// - public FreeSqlBuilder UseSeedData(Action sd) - { - _seedData = new SeedDataBuilder(); - sd?.Invoke(_seedData); - return this; - } } }