- 增加 FreeSql.DbContext OnModelCreating 虚方法,实现在 DbContext 使用 FluentApi;#4 - 移除 FreeSql.Extensions.EfCoreFluentApi,功能移至 FreeSql.DbContext;

This commit is contained in:
28810
2020-04-16 02:58:34 +08:00
parent 43e1529a83
commit 36759402cc
23 changed files with 418 additions and 575 deletions

View File

@ -16,57 +16,8 @@ namespace dbcontext_01
{
public class Program
{
public class Song
{
[Column(IsIdentity = true)]
public int Id { get; set; }
public string BigNumber { get; set; }
[Column(IsVersion = true)]//使用简单
public long versionRow { get; set; }
}
public class SongContext : DbContext
{
public DbSet<Song> Songs { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder builder)
{
builder.UseFreeSql(fsql);
}
}
static IFreeSql fsql;
public static void Main(string[] args)
{
var asse = typeof(FreeSql.Internal.ObjectPool.ObjectPool<>).Assembly;
fsql = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\dd2.db;Pooling=true;Max Pool Size=10")
.UseAutoSyncStructure(true)
.UseLazyLoading(true)
.UseNoneCommandParameter(true)
.UseMonitorCommand(cmd => Trace.WriteLine(cmd.CommandText))
.Build();
using (var ctx = new SongContext())
{
var song = new Song { BigNumber = "1000000000000000000" };
ctx.Songs.Add(song);
ctx.Songs.Update(song);
song.BigNumber = (BigInteger.Parse(song.BigNumber) + 1).ToString();
ctx.Songs.Update(song);
ctx.SaveChanges();
var sql = fsql.Update<Song>().SetSource(song).ToSql();
}
CreateWebHostBuilder(args).Build().Run();
}