Skip to content

Commit 153c791

Browse files
2881028810
authored andcommitted
- 移除 未发布的功能 FreeSqlBuilder.UseSeedData
1 parent 6434be8 commit 153c791

File tree

4 files changed

+9
-86
lines changed

4 files changed

+9
-86
lines changed

Examples/base_entity/Program.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,6 @@ static void Main(string[] args)
6868
//.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")
6969

7070
.UseMonitorCommand(cmd => Console.Write(cmd.CommandText))
71-
.UseSeedData(sd => sd
72-
.Apply(new[]
73-
{
74-
new Products { Id = 1, title = "product-1" },
75-
new Products { Id = 2, title = "product-2" },
76-
new Products { Id = 3, title = "product-3" },
77-
new Products { Id = 4, title = "product-4" }
78-
})
79-
.Apply(new[]
80-
{
81-
new S_SysConfig<TestConfig> { Name = "testkey11", Config = new TestConfig { clicks = 11, title = "testtitle11" } },
82-
new S_SysConfig<TestConfig> { Name = "testkey22", Config = new TestConfig { clicks = 22, title = "testtitle22" } },
83-
new S_SysConfig<TestConfig> { Name = "testkey33", Config = new TestConfig { clicks = 33, title = "testtitle33" } }
84-
})
85-
)
86-
8771
.UseLazyLoading(true)
8872
.Build();
8973
BaseEntity.Initialization(fsql);

FreeSql.DbContext/FreeSql.DbContext.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FreeSql/FreeSql.xml

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FreeSql/FreeSqlBuilder.cs

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -303,71 +303,9 @@ public IFreeSql<TMark> Build<TMark>()
303303
}
304304
}
305305
});
306-
307-
//SeedData
308-
if (_seedData != null && _seedData._data.Any())
309-
{
310-
ret.Aop.SyncStructureAfter += new EventHandler<Aop.SyncStructureAfterEventArgs>((s, e) =>
311-
{
312-
if (_seedData._data.Any() == false) return;
313-
foreach (var et in e.EntityTypes)
314-
{
315-
if (_seedData._data.TryGetValue(et, out var sd) == false) continue;
316-
if (sd.Any() == false) continue;
317-
if (ret.Select<object>().AsType(et).Any()) continue;
318-
ret.Insert<object>()
319-
.AsType(et)
320-
.NoneParameter()
321-
.InsertIdentity()
322-
.AppendData(sd.ToArray())
323-
.ExecuteAffrows();
324-
_seedData._data.TryRemove(et, out var old);
325-
}
326-
});
327-
328-
foreach (var sd in _seedData._data)
329-
{
330-
ret.CodeFirst.SyncStructure(sd.Key);
331-
}
332-
}
333306
}
334307

335308
return ret;
336309
}
337-
338-
public class SeedDataBuilder
339-
{
340-
internal ConcurrentDictionary<Type, List<object>> _data = new ConcurrentDictionary<Type, List<object>>();
341-
public SeedDataBuilder Apply<T>(T data) where T : class
342-
{
343-
if (_data.TryGetValue(typeof(T), out var ds) == false)
344-
_data.TryAdd(typeof(T), ds = new List<object>());
345-
ds.Add(data);
346-
return this;
347-
}
348-
public SeedDataBuilder Apply<T>(T[] data) where T : class
349-
{
350-
return this.Apply(data as IEnumerable<T>);
351-
}
352-
public SeedDataBuilder Apply<T>(IEnumerable<T> data) where T : class
353-
{
354-
foreach (var d in data) this.Apply(d);
355-
return this;
356-
}
357-
}
358-
SeedDataBuilder _seedData;
359-
360-
/// <summary>
361-
/// CodeFirst 初始化种子数据<para></para>
362-
/// 表数据为空时,创建设定的种子数据
363-
/// </summary>
364-
/// <param name="sd"></param>
365-
/// <returns></returns>
366-
public FreeSqlBuilder UseSeedData(Action<SeedDataBuilder> sd)
367-
{
368-
_seedData = new SeedDataBuilder();
369-
sd?.Invoke(_seedData);
370-
return this;
371-
}
372310
}
373311
}

0 commit comments

Comments
 (0)