mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
- 增加 FreeSql.DbContext OnModelCreating 虚方法,实现在 DbContext 使用 FluentApi;#4 - 移除 FreeSql.Extensions.EfCoreFluentApi,功能移至 FreeSql.DbContext;
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user