fix: 修复实体对象无空构造函数时通过Repository操作引发异常的问题,增加Lazy改进并发

This commit is contained in:
xuna
2022-07-26 20:06:26 +08:00
parent aba2e14c5d
commit c33d8c6d39
5 changed files with 18 additions and 13 deletions

View File

@ -197,7 +197,7 @@ namespace FreeSql
var tb = _db.OrmOriginal.CodeFirst.GetTableByEntity(EntityType);
if (tb.Primarys.Length != 1) throw new Exception(DbContextStrings.EntityType_PrimaryKeyIsNotOne(EntityType.Name));
if (tb.Primarys[0].CsType.NullableTypeOrThis() != typeof(TKey).NullableTypeOrThis()) throw new Exception(DbContextStrings.EntityType_PrimaryKeyError(EntityType.Name, typeof(TKey).FullName));
var obj = Activator.CreateInstance(tb.Type);
var obj = tb.Type.CreateInstanceGetDefaultValue();
_db.OrmOriginal.SetEntityValueWithPropertyName(tb.Type, obj, tb.Primarys[0].CsName, id);
var ret = obj as TEntity;
if (ret == null) throw new Exception(DbContextStrings.EntityType_CannotConvert(EntityType.Name, typeof(TEntity).Name));