fix: 无构造函数的对象不跟踪(基本上都是dto对象)

无构造函数的对象不跟踪(基本上都是dto对象),ISelect的ToList和First对象如果没有空的构造函数,则会在CreateEntityState的时候引发异常
This commit is contained in:
xuna 2022-07-25 14:31:33 +08:00 committed by GitHub
parent ef69eba405
commit 78a840bd99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -100,6 +100,7 @@ namespace FreeSql
if (itemType == typeof(object)) return;
if (itemType.FullName.Contains("FreeSqlLazyEntity__")) itemType = itemType.BaseType;
if (_db.OrmOriginal.CodeFirst.GetTableByEntity(itemType)?.Primarys.Any() != true) return;
if (itemType.GetConstructor(System.Type.EmptyTypes) == null) return;
var dbset = _db.Set(itemType);
dbset?.GetType().GetMethod("TrackToList", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(dbset, new object[] { list });
return;