mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	- 修复 SqlServer DbFirst 未获取字段位置的问题;#1204
This commit is contained in:
		@@ -2250,6 +2250,12 @@ FROM ""TestTypeParentInfo_01"" a", asTableSubSql);
 | 
				
			|||||||
            Assert.Equal(2, g.sqlite.Select<ToUpd3Pk>().Where(a => a.name.StartsWith("name")).ToUpdate().Set(a => a.name, "nick?").ExecuteAffrows());
 | 
					            Assert.Equal(2, g.sqlite.Select<ToUpd3Pk>().Where(a => a.name.StartsWith("name")).ToUpdate().Set(a => a.name, "nick?").ExecuteAffrows());
 | 
				
			||||||
            Assert.Equal(5, g.sqlite.Select<ToUpd3Pk>().Count());
 | 
					            Assert.Equal(5, g.sqlite.Select<ToUpd3Pk>().Count());
 | 
				
			||||||
            Assert.Equal(5, g.sqlite.Select<ToUpd3Pk>().Where(a => a.name.StartsWith("nick")).Count());
 | 
					            Assert.Equal(5, g.sqlite.Select<ToUpd3Pk>().Where(a => a.name.StartsWith("nick")).Count());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var sql = g.sqlite.Select<ToUpd3Pk>().Where(a => a.name.StartsWith("name")).ToUpdate().Set(a => a.name, "nick?").Set(a => a.pk3, "pk3?").ToSql();
 | 
				
			||||||
 | 
					            Assert.Equal(@"UPDATE ""ToUpd3Pk"" SET ""name"" = @p_0, ""pk3"" = @p_1 
 | 
				
			||||||
 | 
					WHERE (""pk1"" || ',ftb_upd,' || ""pk2"" || ',ftb_upd,' || ""pk3"" in (select * from (SELECT a.""pk1"" || ',ftb_upd,' || a.""pk2"" || ',ftb_upd,' || a.""pk3"" as as1 
 | 
				
			||||||
 | 
					FROM ""ToUpd3Pk"" a 
 | 
				
			||||||
 | 
					WHERE ((a.""name"") LIKE 'name%')) ftb_upd))", sql);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -289,6 +289,7 @@ where {1}
 | 
				
			|||||||
,a.is_nullable 'isnullable'
 | 
					,a.is_nullable 'isnullable'
 | 
				
			||||||
,a.is_identity 'isidentity'
 | 
					,a.is_identity 'isidentity'
 | 
				
			||||||
,f.text as 'defaultvalue'
 | 
					,f.text as 'defaultvalue'
 | 
				
			||||||
 | 
					,a.column_id as 'position'
 | 
				
			||||||
from sys.columns", loc8.ToString().Replace("a.table_name", "a.object_id"), @"
 | 
					from sys.columns", loc8.ToString().Replace("a.table_name", "a.object_id"), @"
 | 
				
			||||||
left join syscomments f on f.id = a.default_object_id
 | 
					left join syscomments f on f.id = a.default_object_id
 | 
				
			||||||
");
 | 
					");
 | 
				
			||||||
@@ -301,13 +302,13 @@ left join syscomments f on f.id = a.default_object_id
 | 
				
			|||||||
,cast(0 as bit) 'isnullable'
 | 
					,cast(0 as bit) 'isnullable'
 | 
				
			||||||
,a.is_output 'isidentity'
 | 
					,a.is_output 'isidentity'
 | 
				
			||||||
,'' as 'defaultvalue'
 | 
					,'' as 'defaultvalue'
 | 
				
			||||||
 | 
					,1 as 'position'
 | 
				
			||||||
from sys.parameters", loc88.ToString().Replace("a.table_name", "a.object_id"), "");
 | 
					from sys.parameters", loc88.ToString().Replace("a.table_name", "a.object_id"), "");
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                sql = $"use [{db}];{sql};use [{olddatabase}]; ";
 | 
					                sql = $"use [{db}];{sql};use [{olddatabase}]; ";
 | 
				
			||||||
                ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
 | 
					                ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
 | 
				
			||||||
                if (ds == null) return loc1;
 | 
					                if (ds == null) return loc1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                var position = 0;
 | 
					 | 
				
			||||||
                foreach (object[] row in ds)
 | 
					                foreach (object[] row in ds)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    var table_id = string.Concat(row[0]);
 | 
					                    var table_id = string.Concat(row[0]);
 | 
				
			||||||
@@ -320,6 +321,7 @@ from sys.parameters", loc88.ToString().Replace("a.table_name", "a.object_id"), "
 | 
				
			|||||||
                    var is_nullable = bool.Parse(string.Concat(row[7]));
 | 
					                    var is_nullable = bool.Parse(string.Concat(row[7]));
 | 
				
			||||||
                    var is_identity = bool.Parse(string.Concat(row[8]));
 | 
					                    var is_identity = bool.Parse(string.Concat(row[8]));
 | 
				
			||||||
                    var defaultValue = string.Concat(row[9]);
 | 
					                    var defaultValue = string.Concat(row[9]);
 | 
				
			||||||
 | 
					                    var position = int.Parse(string.Concat(row[10]));
 | 
				
			||||||
                    if (max_length == 0) max_length = -1;
 | 
					                    if (max_length == 0) max_length = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    loc3[object_id].Add(column, new DbColumnInfo
 | 
					                    loc3[object_id].Add(column, new DbColumnInfo
 | 
				
			||||||
@@ -334,7 +336,7 @@ from sys.parameters", loc88.ToString().Replace("a.table_name", "a.object_id"), "
 | 
				
			|||||||
                        Table = loc2[object_id],
 | 
					                        Table = loc2[object_id],
 | 
				
			||||||
                        Comment = comment,
 | 
					                        Comment = comment,
 | 
				
			||||||
                        DefaultValue = defaultValue,
 | 
					                        DefaultValue = defaultValue,
 | 
				
			||||||
                        Position = ++position
 | 
					                        Position = position
 | 
				
			||||||
                    });
 | 
					                    });
 | 
				
			||||||
                    loc3[object_id][column].DbType = this.GetDbType(loc3[object_id][column]);
 | 
					                    loc3[object_id][column].DbType = this.GetDbType(loc3[object_id][column]);
 | 
				
			||||||
                    loc3[object_id][column].CsType = this.GetCsTypeInfo(loc3[object_id][column]);
 | 
					                    loc3[object_id][column].CsType = this.GetCsTypeInfo(loc3[object_id][column]);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user