- 增加 EfCoreFluentApi HasData 设定 CodeFirst 种子数据;

- 完善 EfCoreFluentApi 功能测试;
- 增加 DbContextOptions.NoneParameter 设置是否使用参数化执行 Insert/Update;
This commit is contained in:
28810
2020-04-03 08:55:56 +08:00
parent e5cbd407cb
commit 03fe0921ee
18 changed files with 339 additions and 78 deletions

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq.Expressions;
using FreeSql.DataAnnotations;
using FreeSql.Internal.CommonProvider;
namespace FreeSql.Extensions.EfCoreFluentApi
{
@ -10,13 +11,14 @@ namespace FreeSql.Extensions.EfCoreFluentApi
public static ICodeFirst Entity<T>(this ICodeFirst codeFirst, Action<EfCoreTableFluent<T>> modelBuilder)
{
codeFirst.ConfigEntity<T>(tf => modelBuilder(new EfCoreTableFluent<T>(tf)));
var cf = codeFirst as CodeFirstProvider;
codeFirst.ConfigEntity<T>(tf => modelBuilder(new EfCoreTableFluent<T>(cf._orm, tf)));
return codeFirst;
}
static void Test()
public static void Test(IFreeSql fsql)
{
ICodeFirst cf = null;
var cf = fsql.CodeFirst;
cf.Entity<Song>(eb =>
{
eb.ToTable("tb_song");
@ -25,7 +27,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
eb.Property(a => a.Url).HasMaxLength(100);
eb.Property(a => a.RowVersion).IsRowVersion();
eb.Property(a => a.CreateTime).HasDefaultValueSql("getdate()");
eb.Property(a => a.CreateTime).HasDefaultValueSql("current_timestamp");
eb.HasKey(a => a.Id);
eb.HasIndex(a => a.Title).IsUnique().HasName("idx_xxx11");
@ -39,7 +41,33 @@ namespace FreeSql.Extensions.EfCoreFluentApi
cf.Entity<SongType>(eb =>
{
eb.HasMany(a => a.Songs).WithOne(a => a.Type).HasForeignKey(a => a.TypeId);
eb.HasData(new[]
{
new SongType
{
Id = 1,
Name = "流行",
Songs = new List<Song>(new[]
{
new Song{ Title = "真的爱你" },
new Song{ Title = "爱你一万年" },
})
},
new SongType
{
Id = 2,
Name = "乡村",
Songs = new List<Song>(new[]
{
new Song{ Title = "乡里乡亲" },
})
},
});
});
cf.SyncStructure<SongType>();
cf.SyncStructure<Song>();
}
public class SongType
@ -52,6 +80,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
public class Song
{
[Column(IsIdentity = true)]
public int Id { get; set; }
public string Title { get; set; }
public string Url { get; set; }