TEntity CheckTKeyAndReturnIdEntity(TKey id) { 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); _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)); } return(ret); }
public void EntityType_PrimaryKeyIsNotOneTest() { string text = DbContextStrings.EntityType_PrimaryKeyIsNotOne("1"); output.WriteLine(text); }