mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	修复 DbContext bug
This commit is contained in:
		@@ -1,8 +1,12 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Numerics;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using FreeSql;
 | 
			
		||||
using FreeSql.DataAnnotations;
 | 
			
		||||
using Microsoft.AspNetCore;
 | 
			
		||||
using Microsoft.AspNetCore.Hosting;
 | 
			
		||||
using Microsoft.Extensions.Configuration;
 | 
			
		||||
@@ -12,10 +16,49 @@ namespace dbcontext_01
 | 
			
		||||
{
 | 
			
		||||
    public class Program
 | 
			
		||||
    {
 | 
			
		||||
        public static void Main(string[] args)
 | 
			
		||||
        {
 | 
			
		||||
            CreateWebHostBuilder(args).Build().Run();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		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) {
 | 
			
		||||
			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();
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			CreateWebHostBuilder(args).Build().Run();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
 | 
			
		||||
            WebHost.CreateDefaultBuilder(args)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user