Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用OldName和Name组合时,系统运行提示 Table xxx doesn't exist. #1147

Closed
yuanyong00 opened this issue Jun 6, 2022 · 3 comments
Closed

Comments

@yuanyong00
Copy link

问题描述及重现步骤:

1、在任意表中,设置表Table特性,将原有Name改为OldName,再设置新的Name.
2、调试时,能看到生成的SQL语句,
alert table [newName] comment '',然后再出现 alert table [oldName] rename [newName]
报错是第一行产生,先修改评论,再修改表明。

3、如果将评论删除,改名表功能正常。

数据库的具体版本

任意

安装的包

3.0+ 至最新

.net framework/. net core? 及具体版本

.net6
@2881099
Copy link
Collaborator

2881099 commented Jun 6, 2022

sqlserver 测试没有出现你描述的问题:

/// <summary>
/// 用户图片
/// </summary>
[Table(Name = "TUserImg", OldName = "TUserImg01")]
public partial class TUserImg : IEntity
{
    ///<summary>
    ///主键
    ///</summary>
    public string Id { get; set; }
}
use [freesqlTest_odbc];use [freesqlTest_odbc];
EXEC sp_rename N'[freesqlTest_odbc].[dbo].[TUserImg01]', N'TUserImg';

IF ((SELECT COUNT(1) from fn_listextendedproperty('MS_Description', 
  'SCHEMA', N'dbo', 
  'TABLE', N'TUserImg', 
  NULL, NULL)) > 0) 
  EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'用户图片'
    , @level0type = 'SCHEMA', @level0name = N'dbo'
    , @level1type = 'TABLE', @level1name = N'TUserImg'
ELSE
  EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'用户图片'
    , @level0type = 'SCHEMA', @level0name = N'dbo'
    , @level1type = 'TABLE', @level1name = N'TUserImg'

@yuanyong00
Copy link
Author

使用mysql出现了此问题,mySQL版本5.7.27

 /// <summary>
    /// 角色实体
    /// </summary>
    [Table(Name = "sys_role", OldName = "Role")]
    public class RoleEntity : FullEntity
    {
        /// <summary>
        /// 角色名称
        /// </summary>
        [MaxLength(50)]
        public string RoleName { get; set; }

        /// <summary>
        /// 角色说明
        /// </summary>
        [MaxLength(500)]
        public string Description { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsActive { get; set; }

        /// <summary>
        /// 按钮权限
        /// </summary>
        public string BtnRolesCheckedList { get; set; }
    }
select
a.column_name,
a.column_type,
case when a.is_nullable = 'YES' then 1 else 0 end 'is_nullable',
case when locate('auto_increment', a.extra) > 0 then 1 else 0 end 'is_identity',
a.column_comment 'comment'
from information_schema.columns a
where a.table_schema in ('rw.pms.all') and a.table_name in ('Role')

select
a.column_name,
a.index_name 'index_id',
0 'IsDesc',
case when a.non_unique = 0 then 1 else 0 end 'IsUnique'
from information_schema.statistics a
where a.table_schema IN ('rw.pms.all') and a.table_name IN ('Role') and a.index_name <> 'PRIMARY'
 select table_comment from information_schema.tables where table_schema = 'rw.pms.all' and table_name = 'sys_role'
ALTER TABLE `rw.pms.all`.`sys_role` COMMENT  '角色实体';
ALTER TABLE `rw.pms.all`.`Role` RENAME TO `rw.pms.all`.`sys_role`;

@yuanyong00
Copy link
Author

前端报错提示:

{"Code":500,"Msg":"Table \u0027rw.pms.all.sys_role\u0027 doesn\u0027t exist","Desc":"System.Exception: Table \u0027rw.pms.all.sys_role\u0027 doesn\u0027t exist\r\n ---\u003E MySql.Data.MySqlClient.MySqlException (0x80004005): Table \u0027rw.pms.all.sys_role\u0027 doesn\u0027t exist\r\n   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()\r\n   at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32\u0026 affectedRow, Int64\u0026 insertedId)\r\n   at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32\u0026 affectedRows, Int64\u0026 insertedId)\r\n   at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)\r\n   at MySql.Data.MySqlClient.MySqlDataReader.NextResult()\r\n   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)\r\n   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader()\r\n   at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()\r\n   at FreeSql.Internal.CommonProvider.AdoProvider.ExecuteNonQuery(DbConnection connection, DbTransaction transaction, CommandType cmdType, String cmdText, Int32 cmdTimeout, DbParameter[] cmdParms)\r\n   --- End of inner exception stack trace ---\r\n   at FreeSql.Internal.CommonProvider.AdoProvider.LoggerException(IObjectPool\u00601 pool, PrepareCommandResult pc, Exception ex, DateTime dt, StringBuilder logtxt, Boolean isThrowException)\r\n   at FreeSql.Internal.CommonProvider.AdoProvider.ExecuteNonQuery(DbConnection connection, DbTransaction transaction, CommandType cmdType, String cmdText, Int32 cmdTimeout, DbParameter[] cmdParms)\r\n   at FreeSql.Internal.CommonProvider.AdoProvider.ExecuteNonQuery(CommandType cmdType, String cmdText, DbParameter[] cmdParms)\r\n   at FreeSql.Internal.CommonProvider.CodeFirstProvider.ExecuteDDLStatements(String ddl)\r\n   at FreeSql.Internal.CommonProvider.CodeFirstProvider.SyncStructure(TypeAndName[] objects)\r\n   at FreeSql.Internal.CommonProvider.CodeFirstProvider.SyncStructure[TEntity]()\r\n   at FreeSql.Internal.CommonProvider.Select0Provider\u00602..ctor(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, Object dywhere)\r\n   at FreeSql.Internal.CommonProvider.Select1Provider\u00601..ctor(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, Object dywhere)\r\n   at FreeSql.MySql.Curd.MySqlSelect\u00601..ctor(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, Object dywhere)\r\n   at FreeSql.MySql.MySqlProvider\u00601.CreateSelectProvider[T1](Object dywhere)\r\n   at FreeSql.Internal.CommonProvider.BaseDbProvider.Select[T1]()\r\n   at FreeSql.DbSet\u00601.OrmSelect(Object dywhere)\r\n   at FreeSql.RepositoryDbSet\u00601.OrmSelect(Object dywhere)\r\n   at FreeSql.RepositoryDbSet\u00601.OrmSelectInternal(Object dywhere)\r\n   at FreeSql.BaseRepository\u00601.get_Select()\r\n   at FreeSql.BaseRepository\u00601.WhereIf(Boolean condition, Expression\u00601 exp)\r\n   at RW.PMS.Application.System.RoleService.GetPagedList(RoleSearchDto input) in G:\\src\\pms\\src\\service\\RW.PMS.Application\\System\\RoleService.cs:line 49\r\n   at Castle.Proxies.Invocations.IRoleService_GetPagedList.InvokeMethodOnTarget()\r\n   at Castle.DynamicProxy.AbstractInvocation.Proceed()\r\n   at RW.PMS.CrossCutting.AOP.Interceptors.DatabaseTransactionAsync.InterceptSynchronous(IInvocation invocation) in G:\\src\\pms\\src\\service\\RW.PMS.CrossCutting\\AOP\\Interceptors\\DatabaseTransactionAsync.cs:line 41\r\n   at Castle.DynamicProxy.AsyncDeterminationInterceptor.Intercept(IInvocation invocation)\r\n   at RW.PMS.CrossCutting.AOP.Interceptors.DatabaseTransaction.Intercept(IInvocation invocation) in G:\\src\\pms\\src\\service\\RW.PMS.CrossCutting\\AOP\\Interceptors\\DatabaseTransaction.cs:line 16\r\n   at Castle.DynamicProxy.AbstractInvocation.Proceed()\r\n   at Castle.Proxies.IApplicationServiceProxy_4.GetPagedList(RoleSearchDto input)\r\n   at RW.PMS.API.Controllers.RoleController.GetList(RoleSearchDto input) in G:\\src\\pms\\src\\service\\RW.PMS.API\\Controllers\\RoleController.cs:line 23\r\n   at lambda_method526(Closure , Object , Object[] )\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State\u0026 next, Scope\u0026 scope, Object\u0026 state, Boolean\u0026 isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()\r\n--- End of stack trace from previous location ---\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State\u0026 next, Scope\u0026 scope, Object\u0026 state, Boolean\u0026 isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()\r\n--- End of stack trace from previous location ---\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.\u003CInvokeNextResourceFilter\u003Eg__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State\u0026 next, Scope\u0026 scope, Object\u0026 state, Boolean\u0026 isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()\r\n--- End of stack trace from previous location ---\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.\u003CInvokeAsync\u003Eg__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.\u003CInvokeAsync\u003Eg__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)\r\n   at Microsoft.AspNetCore.Routing.EndpointMiddleware.\u003CInvoke\u003Eg__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)\r\n   at Microsoft.AspNetCore.Authorization.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult)\r\n   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)\r\n   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)\r\n   at RW.PMS.API.Middleware.ExceptionMiddleWare.InvokeAsync(HttpContext context, RequestDelegate next) in G:\\src\\pms\\src\\service\\RW.PMS.API\\Middleware\\ExceptionMiddleWare.cs:line 22"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants