mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	源代码改用vs默认格式化
This commit is contained in:
		@@ -19,93 +19,101 @@ namespace dbcontext_01
 | 
			
		||||
        {
 | 
			
		||||
            Configuration = configuration;
 | 
			
		||||
 | 
			
		||||
			Fsql = new FreeSql.FreeSqlBuilder()
 | 
			
		||||
				.UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\document2.db;Pooling=true;Max Pool Size=10")
 | 
			
		||||
				//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=10")
 | 
			
		||||
            Fsql = new FreeSql.FreeSqlBuilder()
 | 
			
		||||
                .UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\document2.db;Pooling=true;Max Pool Size=10")
 | 
			
		||||
                //.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=10")
 | 
			
		||||
 | 
			
		||||
				//.UseConnectionString(FreeSql.DataType.Oracle, "user id=user1;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=10")
 | 
			
		||||
				//.UseSyncStructureToUpper(true)
 | 
			
		||||
                //.UseConnectionString(FreeSql.DataType.Oracle, "user id=user1;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=10")
 | 
			
		||||
                //.UseSyncStructureToUpper(true)
 | 
			
		||||
 | 
			
		||||
				.UseAutoSyncStructure(true)
 | 
			
		||||
				.UseLazyLoading(true)
 | 
			
		||||
				.UseNoneCommandParameter(true)
 | 
			
		||||
                .UseAutoSyncStructure(true)
 | 
			
		||||
                .UseLazyLoading(true)
 | 
			
		||||
                .UseNoneCommandParameter(true)
 | 
			
		||||
 | 
			
		||||
				.UseMonitorCommand(cmd => Trace.WriteLine(cmd.CommandText),
 | 
			
		||||
					(cmd, log) => Trace.WriteLine(log)
 | 
			
		||||
				)
 | 
			
		||||
				.Build();
 | 
			
		||||
			Fsql.Aop.SyncStructureBefore = (s, e) => {
 | 
			
		||||
				Console.WriteLine(e.Identifier + ": " + string.Join(", ", e.EntityTypes.Select(a => a.FullName)));
 | 
			
		||||
			};
 | 
			
		||||
			Fsql.Aop.SyncStructureAfter = (s, e) => {
 | 
			
		||||
				Console.WriteLine(e.Identifier + ": " + string.Join(", ", e.EntityTypes.Select(a => a.FullName)) + " " + e.ElapsedMilliseconds + "ms\r\n" + e.Exception?.Message + e.Sql);
 | 
			
		||||
			};
 | 
			
		||||
                .UseMonitorCommand(cmd => Trace.WriteLine(cmd.CommandText),
 | 
			
		||||
                    (cmd, log) => Trace.WriteLine(log)
 | 
			
		||||
                )
 | 
			
		||||
                .Build();
 | 
			
		||||
            Fsql.Aop.SyncStructureBefore = (s, e) =>
 | 
			
		||||
            {
 | 
			
		||||
                Console.WriteLine(e.Identifier + ": " + string.Join(", ", e.EntityTypes.Select(a => a.FullName)));
 | 
			
		||||
            };
 | 
			
		||||
            Fsql.Aop.SyncStructureAfter = (s, e) =>
 | 
			
		||||
            {
 | 
			
		||||
                Console.WriteLine(e.Identifier + ": " + string.Join(", ", e.EntityTypes.Select(a => a.FullName)) + " " + e.ElapsedMilliseconds + "ms\r\n" + e.Exception?.Message + e.Sql);
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
			Fsql.Aop.CurdBefore = (s, e) => {
 | 
			
		||||
				Console.WriteLine(e.Identifier + ": " + e.EntityType.FullName + ", " + e.Sql);
 | 
			
		||||
			};
 | 
			
		||||
			Fsql.Aop.CurdAfter = (s, e) => {
 | 
			
		||||
				Console.WriteLine(e.Identifier + ": " + e.EntityType.FullName + " " + e.ElapsedMilliseconds + "ms, " + e.Sql);
 | 
			
		||||
			};
 | 
			
		||||
            Fsql.Aop.CurdBefore = (s, e) =>
 | 
			
		||||
            {
 | 
			
		||||
                Console.WriteLine(e.Identifier + ": " + e.EntityType.FullName + ", " + e.Sql);
 | 
			
		||||
            };
 | 
			
		||||
            Fsql.Aop.CurdAfter = (s, e) =>
 | 
			
		||||
            {
 | 
			
		||||
                Console.WriteLine(e.Identifier + ": " + e.EntityType.FullName + " " + e.ElapsedMilliseconds + "ms, " + e.Sql);
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
			Fsql2 = new FreeSql.FreeSqlBuilder()
 | 
			
		||||
				.UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\document222.db;Pooling=true;Max Pool Size=10")
 | 
			
		||||
				//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=10")
 | 
			
		||||
				.UseAutoSyncStructure(true)
 | 
			
		||||
				.UseLazyLoading(true)
 | 
			
		||||
            Fsql2 = new FreeSql.FreeSqlBuilder()
 | 
			
		||||
                .UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\document222.db;Pooling=true;Max Pool Size=10")
 | 
			
		||||
                //.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=10")
 | 
			
		||||
                .UseAutoSyncStructure(true)
 | 
			
		||||
                .UseLazyLoading(true)
 | 
			
		||||
 | 
			
		||||
				.UseMonitorCommand(cmd => Trace.WriteLine(cmd.CommandText),
 | 
			
		||||
					(cmd, log) => Trace.WriteLine(log)
 | 
			
		||||
				)
 | 
			
		||||
				.Build<long>();
 | 
			
		||||
		}
 | 
			
		||||
                .UseMonitorCommand(cmd => Trace.WriteLine(cmd.CommandText),
 | 
			
		||||
                    (cmd, log) => Trace.WriteLine(log)
 | 
			
		||||
                )
 | 
			
		||||
                .Build<long>();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		enum MySql { }
 | 
			
		||||
		enum PgSql { }
 | 
			
		||||
        enum MySql { }
 | 
			
		||||
        enum PgSql { }
 | 
			
		||||
 | 
			
		||||
		public IConfiguration Configuration { get; }
 | 
			
		||||
		public static IFreeSql Fsql { get; private set; }
 | 
			
		||||
		public static IFreeSql<long> Fsql2 { get; private set; }
 | 
			
		||||
        public IConfiguration Configuration { get; }
 | 
			
		||||
        public static IFreeSql Fsql { get; private set; }
 | 
			
		||||
        public static IFreeSql<long> Fsql2 { get; private set; }
 | 
			
		||||
 | 
			
		||||
		public void ConfigureServices(IServiceCollection services)
 | 
			
		||||
        public void ConfigureServices(IServiceCollection services)
 | 
			
		||||
        {
 | 
			
		||||
			services.AddMvc();
 | 
			
		||||
			services.AddSwaggerGen(options => {
 | 
			
		||||
				options.SwaggerDoc("v1", new Info {
 | 
			
		||||
					Version = "v1",
 | 
			
		||||
					Title = "FreeSql.DbContext API"
 | 
			
		||||
				});
 | 
			
		||||
				//options.IncludeXmlComments(xmlPath);
 | 
			
		||||
			});
 | 
			
		||||
            services.AddMvc();
 | 
			
		||||
            services.AddSwaggerGen(options =>
 | 
			
		||||
            {
 | 
			
		||||
                options.SwaggerDoc("v1", new Info
 | 
			
		||||
                {
 | 
			
		||||
                    Version = "v1",
 | 
			
		||||
                    Title = "FreeSql.DbContext API"
 | 
			
		||||
                });
 | 
			
		||||
                //options.IncludeXmlComments(xmlPath);
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
			services.AddSingleton<IFreeSql>(Fsql);
 | 
			
		||||
			services.AddSingleton<IFreeSql<long>>(Fsql2);
 | 
			
		||||
			services.AddFreeDbContext<SongContext>(options => options.UseFreeSql(Fsql));
 | 
			
		||||
            services.AddSingleton<IFreeSql>(Fsql);
 | 
			
		||||
            services.AddSingleton<IFreeSql<long>>(Fsql2);
 | 
			
		||||
            services.AddFreeDbContext<SongContext>(options => options.UseFreeSql(Fsql));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
			var sql1 = Fsql.Update<Song>(1).Set(a => a.Id + 10).ToSql();
 | 
			
		||||
			var sql2 = Fsql.Update<Song>(1).Set(a => a.Title + 10).ToSql();
 | 
			
		||||
			var sql3 = Fsql.Update<Song>(1).Set(a => a.Create_time.Value.AddHours(1)).ToSql();
 | 
			
		||||
		}
 | 
			
		||||
            var sql1 = Fsql.Update<Song>(1).Set(a => a.Id + 10).ToSql();
 | 
			
		||||
            var sql2 = Fsql.Update<Song>(1).Set(a => a.Title + 10).ToSql();
 | 
			
		||||
            var sql3 = Fsql.Update<Song>(1).Set(a => a.Create_time.Value.AddHours(1)).ToSql();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) {
 | 
			
		||||
			Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
 | 
			
		||||
			Console.OutputEncoding = Encoding.GetEncoding("GB2312");
 | 
			
		||||
			Console.InputEncoding = Encoding.GetEncoding("GB2312");
 | 
			
		||||
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
 | 
			
		||||
        {
 | 
			
		||||
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
 | 
			
		||||
            Console.OutputEncoding = Encoding.GetEncoding("GB2312");
 | 
			
		||||
            Console.InputEncoding = Encoding.GetEncoding("GB2312");
 | 
			
		||||
 | 
			
		||||
			loggerFactory.AddConsole(Configuration.GetSection("Logging"));
 | 
			
		||||
			loggerFactory.AddDebug();
 | 
			
		||||
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
 | 
			
		||||
            loggerFactory.AddDebug();
 | 
			
		||||
 | 
			
		||||
			app.UseHttpMethodOverride(new HttpMethodOverrideOptions { FormFieldName = "X-Http-Method-Override" });
 | 
			
		||||
			app.UseDeveloperExceptionPage();
 | 
			
		||||
			app.UseMvc();
 | 
			
		||||
            app.UseHttpMethodOverride(new HttpMethodOverrideOptions { FormFieldName = "X-Http-Method-Override" });
 | 
			
		||||
            app.UseDeveloperExceptionPage();
 | 
			
		||||
            app.UseMvc();
 | 
			
		||||
 | 
			
		||||
			app.UseSwagger();
 | 
			
		||||
			app.UseSwaggerUI(c => {
 | 
			
		||||
				c.SwaggerEndpoint("/swagger/v1/swagger.json", "FreeSql.RESTful API V1");
 | 
			
		||||
			});
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
            app.UseSwagger();
 | 
			
		||||
            app.UseSwaggerUI(c =>
 | 
			
		||||
            {
 | 
			
		||||
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "FreeSql.RESTful API V1");
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user