mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 17:20:49 +08:00 
			
		
		
		
	v0.1.4 判断 SqlServer 服务器版本,选择分页模式 row_number 或 offset fetch next;
This commit is contained in:
		@@ -2,7 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  <PropertyGroup>
 | 
					  <PropertyGroup>
 | 
				
			||||||
    <TargetFramework>netstandard2.0</TargetFramework>
 | 
					    <TargetFramework>netstandard2.0</TargetFramework>
 | 
				
			||||||
    <Version>0.1.3</Version>
 | 
					    <Version>0.1.4</Version>
 | 
				
			||||||
    <Authors>YeXiangQin</Authors>
 | 
					    <Authors>YeXiangQin</Authors>
 | 
				
			||||||
    <Description>FreeSql 通用仓库层现实,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。</Description>
 | 
					    <Description>FreeSql 通用仓库层现实,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。</Description>
 | 
				
			||||||
    <PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl>
 | 
					    <PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -50,7 +50,11 @@ namespace FreeSql.Tests.SqlServer {
 | 
				
			|||||||
			//	.LeftJoin<xxx>((a, b) => b.Id == a.Id)
 | 
								//	.LeftJoin<xxx>((a, b) => b.Id == a.Id)
 | 
				
			||||||
			//	.ToList(a => new { a.Id, a.Title });
 | 
								//	.ToList(a => new { a.Id, a.Title });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			var tn = g.sqlserver.Select<xxx>().Where(a => a.Id > 0).Where(b => b.Title != null).ToList(a => a.Id);
 | 
								var tnsql1 = g.sqlserver.Select<xxx>().Where(a => a.Id > 0).Where(b => b.Title != null).Page(1, 3).ToSql(a => a.Id);
 | 
				
			||||||
 | 
								var tnsql2 = g.sqlserver.Select<xxx>().Where(a => a.Id > 0).Where(b => b.Title != null).Page(2, 3).ToSql(a => a.Id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								var tn1 = g.sqlserver.Select<xxx>().Where(a => a.Id > 0).Where(b => b.Title != null).Page(1, 3).ToList(a => a.Id);
 | 
				
			||||||
 | 
								var tn2 = g.sqlserver.Select<xxx>().Where(a => a.Id > 0).Where(b => b.Title != null).Page(2, 3).ToList(a => a.Id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			var t3 = g.sqlserver.Ado.Query<xxx>("select * from song");
 | 
								var t3 = g.sqlserver.Ado.Query<xxx>("select * from song");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,7 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  <PropertyGroup>
 | 
					  <PropertyGroup>
 | 
				
			||||||
    <TargetFramework>netstandard2.0</TargetFramework>
 | 
					    <TargetFramework>netstandard2.0</TargetFramework>
 | 
				
			||||||
    <Version>0.1.3</Version>
 | 
					    <Version>0.1.4</Version>
 | 
				
			||||||
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
 | 
					    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
 | 
				
			||||||
    <Authors>YeXiangQin</Authors>
 | 
					    <Authors>YeXiangQin</Authors>
 | 
				
			||||||
    <Description>打造 .NETCore 最方便的 ORM,DbFirst 与 CodeFirst 混合使用,提供从实体同步数据库,或者从数据库生成实体代码,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。</Description>
 | 
					    <Description>打造 .NETCore 最方便的 ORM,DbFirst 与 CodeFirst 混合使用,提供从实体同步数据库,或者从数据库生成实体代码,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。</Description>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,7 +11,9 @@ namespace FreeSql.SqlServer.Curd {
 | 
				
			|||||||
	class SqlServerSelect<T1> : FreeSql.Internal.CommonProvider.Select1Provider<T1> where T1 : class {
 | 
						class SqlServerSelect<T1> : FreeSql.Internal.CommonProvider.Select1Provider<T1> where T1 : class {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		internal static string ToSqlStatic(CommonUtils _commonUtils, string _select, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, IFreeSql _orm)
 | 
							internal static string ToSqlStatic(CommonUtils _commonUtils, string _select, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, IFreeSql _orm)
 | 
				
			||||||
			=> ToSqlStaticRowNumber(_commonUtils, _select, field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
								=> (_commonUtils as SqlServerUtils).IsSelectRowNumber ?
 | 
				
			||||||
 | 
								ToSqlStaticRowNumber(_commonUtils, _select, field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm) :
 | 
				
			||||||
 | 
								ToSqlStaticOffsetFetchNext(_commonUtils, _select, field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		#region SqlServer 2005 row_number
 | 
							#region SqlServer 2005 row_number
 | 
				
			||||||
		internal static string ToSqlStaticRowNumber(CommonUtils _commonUtils, string _select, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, IFreeSql _orm) {
 | 
							internal static string ToSqlStaticRowNumber(CommonUtils _commonUtils, string _select, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, IFreeSql _orm) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,6 +36,13 @@ namespace FreeSql.SqlServer {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			this.DbFirst = new SqlServerDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
 | 
								this.DbFirst = new SqlServerDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
 | 
				
			||||||
			this.CodeFirst = new SqlServerCodeFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
 | 
								this.CodeFirst = new SqlServerCodeFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								using (var conn = this.Ado.MasterPool.Get()) {
 | 
				
			||||||
 | 
									try {
 | 
				
			||||||
 | 
										(this.InternalCommonUtils as SqlServerUtils).IsSelectRowNumber = int.Parse(conn.Value.ServerVersion.Split('.')[0]) <= 10;
 | 
				
			||||||
 | 
									} catch {
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		internal CommonUtils InternalCommonUtils { get; }
 | 
							internal CommonUtils InternalCommonUtils { get; }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,6 +11,8 @@ namespace FreeSql.SqlServer {
 | 
				
			|||||||
		public SqlServerUtils(IFreeSql orm) : base(orm) {
 | 
							public SqlServerUtils(IFreeSql orm) : base(orm) {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							internal bool IsSelectRowNumber = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		internal override DbParameter AppendParamter(List<DbParameter> _params, string parameterName, Type type, object value) {
 | 
							internal override DbParameter AppendParamter(List<DbParameter> _params, string parameterName, Type type, object value) {
 | 
				
			||||||
			if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}";
 | 
								if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}";
 | 
				
			||||||
			else if (_orm.CodeFirst.IsSyncStructureToLower) parameterName = parameterName.ToLower();
 | 
								else if (_orm.CodeFirst.IsSyncStructureToLower) parameterName = parameterName.ToLower();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user