mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 17:20:49 +08:00 
			
		
		
		
	- 修复 CodeFirst IsNullable 迁移脚本重复 NOT NULL 语法错误;
This commit is contained in:
		@@ -21,6 +21,9 @@ namespace FreeSql.Tests.MySqlConnector
 | 
				
			|||||||
            public Guid Id { get; set; }
 | 
					            public Guid Id { get; set; }
 | 
				
			||||||
            [Column(StringLength = 50)]
 | 
					            [Column(StringLength = 50)]
 | 
				
			||||||
            public string Title { get; set; }
 | 
					            public string Title { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            [Column(IsNullable = false, StringLength = 50)]
 | 
				
			||||||
 | 
					            public string TitleSub { get; set; }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,9 @@ namespace FreeSql.Tests.Odbc.Dameng
 | 
				
			|||||||
            public Guid Id { get; set; }
 | 
					            public Guid Id { get; set; }
 | 
				
			||||||
            [Column(StringLength = 50)]
 | 
					            [Column(StringLength = 50)]
 | 
				
			||||||
            public string Title { get; set; }
 | 
					            public string Title { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            [Column(IsNullable = false, StringLength = 50)]
 | 
				
			||||||
 | 
					            public string TitleSub { get; set; }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,9 @@ namespace FreeSql.Tests.Odbc.MySql
 | 
				
			|||||||
            public Guid Id { get; set; }
 | 
					            public Guid Id { get; set; }
 | 
				
			||||||
            [Column(StringLength = 50)]
 | 
					            [Column(StringLength = 50)]
 | 
				
			||||||
            public string Title { get; set; }
 | 
					            public string Title { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            [Column(IsNullable = false, StringLength = 50)]
 | 
				
			||||||
 | 
					            public string TitleSub { get; set; }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,9 @@ namespace FreeSql.Tests.Odbc.Oracle
 | 
				
			|||||||
            public Guid Id { get; set; }
 | 
					            public Guid Id { get; set; }
 | 
				
			||||||
            [Column(StringLength = 50)]
 | 
					            [Column(StringLength = 50)]
 | 
				
			||||||
            public string Title { get; set; }
 | 
					            public string Title { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            [Column(IsNullable = false, StringLength = 50)]
 | 
				
			||||||
 | 
					            public string TitleSub { get; set; }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,6 +25,9 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
 | 
				
			|||||||
            public Guid Id { get; set; }
 | 
					            public Guid Id { get; set; }
 | 
				
			||||||
            [Column(StringLength = 50)]
 | 
					            [Column(StringLength = 50)]
 | 
				
			||||||
            public string Title { get; set; }
 | 
					            public string Title { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            [Column(IsNullable = false, StringLength = 50)]
 | 
				
			||||||
 | 
					            public string TitleSub { get; set; }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,6 +23,9 @@ namespace FreeSql.Tests.Odbc.SqlServer
 | 
				
			|||||||
            public Guid Id { get; set; }
 | 
					            public Guid Id { get; set; }
 | 
				
			||||||
            [Column(StringLength = 50)]
 | 
					            [Column(StringLength = 50)]
 | 
				
			||||||
            public string Title { get; set; }
 | 
					            public string Title { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            [Column(IsNullable = false, StringLength = 50)]
 | 
				
			||||||
 | 
					            public string TitleSub { get; set; }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,9 @@ namespace FreeSql.Tests.MsAccess
 | 
				
			|||||||
            public Guid Id { get; set; }
 | 
					            public Guid Id { get; set; }
 | 
				
			||||||
            [Column(StringLength = 50)]
 | 
					            [Column(StringLength = 50)]
 | 
				
			||||||
            public string Title { get; set; }
 | 
					            public string Title { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            [Column(IsNullable = false, StringLength = 50)]
 | 
				
			||||||
 | 
					            public string TitleSub { get; set; }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,9 @@ namespace FreeSql.Tests.MySql
 | 
				
			|||||||
            public Guid Id { get; set; }
 | 
					            public Guid Id { get; set; }
 | 
				
			||||||
            [Column(StringLength = 50)]
 | 
					            [Column(StringLength = 50)]
 | 
				
			||||||
            public string Title { get; set; }
 | 
					            public string Title { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            [Column(IsNullable = false, StringLength = 50)]
 | 
				
			||||||
 | 
					            public string TitleSub { get; set; }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,9 @@ namespace FreeSql.Tests.Oracle
 | 
				
			|||||||
            public Guid Id { get; set; }
 | 
					            public Guid Id { get; set; }
 | 
				
			||||||
            [Column(StringLength = 50)]
 | 
					            [Column(StringLength = 50)]
 | 
				
			||||||
            public string Title { get; set; }
 | 
					            public string Title { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            [Column(IsNullable = false, StringLength = 50)]
 | 
				
			||||||
 | 
					            public string TitleSub { get; set; }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,6 +28,9 @@ namespace FreeSql.Tests.PostgreSQL
 | 
				
			|||||||
            public Guid Id { get; set; }
 | 
					            public Guid Id { get; set; }
 | 
				
			||||||
            [Column(StringLength = 50)]
 | 
					            [Column(StringLength = 50)]
 | 
				
			||||||
            public string Title { get; set; }
 | 
					            public string Title { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            [Column(IsNullable = false, StringLength = 50)]
 | 
				
			||||||
 | 
					            public string TitleSub { get; set; }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,6 +22,9 @@ namespace FreeSql.Tests.SqlServer
 | 
				
			|||||||
            public Guid Id { get; set; }
 | 
					            public Guid Id { get; set; }
 | 
				
			||||||
            [Column(StringLength = 50)]
 | 
					            [Column(StringLength = 50)]
 | 
				
			||||||
            public string Title { get; set; }
 | 
					            public string Title { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            [Column(IsNullable = false, StringLength = 50)]
 | 
				
			||||||
 | 
					            public string TitleSub { get; set; }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,9 @@ namespace FreeSql.Tests.Sqlite
 | 
				
			|||||||
            public Guid Id { get; set; }
 | 
					            public Guid Id { get; set; }
 | 
				
			||||||
            [Column(StringLength = 50)]
 | 
					            [Column(StringLength = 50)]
 | 
				
			||||||
            public string Title { get; set; }
 | 
					            public string Title { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            [Column(IsNullable = false, StringLength = 50)]
 | 
				
			||||||
 | 
					            public string TitleSub { get; set; }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -124,7 +124,7 @@ namespace FreeSql.Internal
 | 
				
			|||||||
                if ((colattr.IsNullable != true || colattr.IsIdentity == true || colattr.IsPrimary == true) && colattr.DbType.Contains("NOT NULL") == false)
 | 
					                if ((colattr.IsNullable != true || colattr.IsIdentity == true || colattr.IsPrimary == true) && colattr.DbType.Contains("NOT NULL") == false)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    colattr.IsNullable = false;
 | 
					                    colattr.IsNullable = false;
 | 
				
			||||||
                    colattr.DbType += " NOT NULL";
 | 
					                    colattr.DbType = Regex.Replace(colattr.DbType, @"\bNULL\b", "").Trim() + " NOT NULL";
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                if (colattr.IsNullable == true && colattr.DbType.Contains("NOT NULL")) colattr.DbType = colattr.DbType.Replace("NOT NULL", "");
 | 
					                if (colattr.IsNullable == true && colattr.DbType.Contains("NOT NULL")) colattr.DbType = colattr.DbType.Replace("NOT NULL", "");
 | 
				
			||||||
                colattr.DbType = Regex.Replace(colattr.DbType, @"\([^\)]+\)", m =>
 | 
					                colattr.DbType = Regex.Replace(colattr.DbType, @"\([^\)]+\)", m =>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user