mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	- 优化 ICodeFirst.SyncStructure 错误提示,当使用不可迁移实体时;
This commit is contained in:
		@@ -9,6 +9,7 @@ using NpgsqlTypes;
 | 
			
		||||
using Npgsql.LegacyPostgis;
 | 
			
		||||
using System.Linq.Expressions;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using System.Collections;
 | 
			
		||||
 | 
			
		||||
namespace FreeSql.Tests {
 | 
			
		||||
	public class UnitTest1 {
 | 
			
		||||
@@ -112,9 +113,24 @@ namespace FreeSql.Tests {
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public class TestEnumable : IEnumerable<TestEnumable> {
 | 
			
		||||
			public IEnumerator<TestEnumable> GetEnumerator() {
 | 
			
		||||
				throw new NotImplementedException();
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			IEnumerator IEnumerable.GetEnumerator() {
 | 
			
		||||
				throw new NotImplementedException();
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		[Fact]
 | 
			
		||||
		public void Test1() {
 | 
			
		||||
 | 
			
		||||
			g.sqlite.CodeFirst.SyncStructure<TestEnumable>();
 | 
			
		||||
 | 
			
		||||
			var TestEnumable = new TestEnumable();
 | 
			
		||||
			
 | 
			
		||||
 | 
			
		||||
			g.sqlite.GetRepository<Model1, int>().Insert(new Model1 {
 | 
			
		||||
				title = "test_" + DateTime.Now.ToString("yyyyMMddHHmmss"),
 | 
			
		||||
				M2Id = DateTime.Now.Second + DateTime.Now.Minute,
 | 
			
		||||
 
 | 
			
		||||
@@ -35,7 +35,7 @@ namespace FreeSql.Internal {
 | 
			
		||||
			var tbc = _cacheGetTableByEntity.GetOrAdd(common._orm.Ado.DataType, k1 => new ConcurrentDictionary<Type, TableInfo>()); //区分数据库类型缓存
 | 
			
		||||
			if (tbc.TryGetValue(entity, out var trytb)) return trytb;
 | 
			
		||||
			if (common.CodeFirst.GetDbInfo(entity) != null) return null;
 | 
			
		||||
			if (typeof(IEnumerable).IsAssignableFrom(entity)) return null;
 | 
			
		||||
			if (typeof(IEnumerable).IsAssignableFrom(entity) && entity.IsGenericParameter == true) return null;
 | 
			
		||||
			if (entity.IsArray) return null;
 | 
			
		||||
 | 
			
		||||
			var tbattr = common.GetEntityTableAttribute(entity);
 | 
			
		||||
 
 | 
			
		||||
@@ -106,6 +106,8 @@ namespace FreeSql.MySql {
 | 
			
		||||
				foreach (var entityType in entityTypes) {
 | 
			
		||||
					if (sb.Length > 0) sb.Append("\r\n");
 | 
			
		||||
					var tb = _commonUtils.GetTableByEntity(entityType);
 | 
			
		||||
					if (tb == null) throw new Exception($"类型 {entityType.FullName} 不可迁移");
 | 
			
		||||
					if (tb.Columns.Any() == false) throw new Exception($"类型 {entityType.FullName} 不可迁移,可迁移属性0个");
 | 
			
		||||
					var tbname = tb.DbName.Split(new[] { '.' }, 2);
 | 
			
		||||
					if (tbname?.Length == 1) tbname = new[] { database, tbname[0] };
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -88,6 +88,8 @@ namespace FreeSql.Oracle {
 | 
			
		||||
			foreach (var entityType in entityTypes) {
 | 
			
		||||
				if (sb.Length > 0) sb.Append("\r\n");
 | 
			
		||||
				var tb = _commonUtils.GetTableByEntity(entityType);
 | 
			
		||||
				if (tb == null) throw new Exception($"类型 {entityType.FullName} 不可迁移");
 | 
			
		||||
				if (tb.Columns.Any() == false) throw new Exception($"类型 {entityType.FullName} 不可迁移,可迁移属性0个");
 | 
			
		||||
				var tbname = tb.DbName.Split(new[] { '.' }, 2);
 | 
			
		||||
				if (tbname?.Length == 1) tbname = new[] { userId, tbname[0] };
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -131,6 +131,8 @@ namespace FreeSql.PostgreSQL {
 | 
			
		||||
			foreach (var entityType in entityTypes) {
 | 
			
		||||
				if (sb.Length > 0) sb.Append("\r\n");
 | 
			
		||||
				var tb = _commonUtils.GetTableByEntity(entityType);
 | 
			
		||||
				if (tb == null) throw new Exception($"类型 {entityType.FullName} 不可迁移");
 | 
			
		||||
				if (tb.Columns.Any() == false) throw new Exception($"类型 {entityType.FullName} 不可迁移,可迁移属性0个");
 | 
			
		||||
				var tbname = tb.DbName.Split(new[] { '.' }, 2);
 | 
			
		||||
				if (tbname?.Length == 1) tbname = new[] { "public", tbname[0] };
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -98,6 +98,8 @@ namespace FreeSql.SqlServer {
 | 
			
		||||
				foreach (var entityType in entityTypes) {
 | 
			
		||||
					if (sb.Length > 0) sb.Append("\r\n");
 | 
			
		||||
					var tb = _commonUtils.GetTableByEntity(entityType);
 | 
			
		||||
					if (tb == null) throw new Exception($"类型 {entityType.FullName} 不可迁移");
 | 
			
		||||
					if (tb.Columns.Any() == false) throw new Exception($"类型 {entityType.FullName} 不可迁移,可迁移属性0个");
 | 
			
		||||
					var tbname = tb.DbName.Split(new[] { '.' }, 3);
 | 
			
		||||
					if (tbname?.Length == 1) tbname = new[] { database, "dbo", tbname[0] };
 | 
			
		||||
					if (tbname?.Length == 2) tbname = new[] { database, tbname[0], tbname[1] };
 | 
			
		||||
 
 | 
			
		||||
@@ -83,6 +83,8 @@ namespace FreeSql.Sqlite {
 | 
			
		||||
			foreach (var entityType in entityTypes) {
 | 
			
		||||
				if (sb.Length > 0) sb.Append("\r\n");
 | 
			
		||||
				var tb = _commonUtils.GetTableByEntity(entityType);
 | 
			
		||||
				if (tb == null) throw new Exception($"类型 {entityType.FullName} 不可迁移");
 | 
			
		||||
				if (tb.Columns.Any() == false) throw new Exception($"类型 {entityType.FullName} 不可迁移,可迁移属性0个");
 | 
			
		||||
				var tbname = tb.DbName.Split(new[] { '.' }, 2);
 | 
			
		||||
				if (tbname?.Length == 1) tbname = new[] { "main", tbname[0] };
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user