DeleteByIdAsync(dynamic id) 问题 返回

C#论坛 老数据
4 2524


使用SimpleClient 的 DeleteByIdAsync(dynamic id)时发生以下错误:


System.AggregateException: One or more errors occurred. ('int' does not contain a definition for 'GetAwaiter')

 ---> Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'int' does not contain a definition for 'GetAwaiter'

   at CallSite.Target(Closure , CallSite , Object )

   at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)

   at SqlSugar.SimpleClient`1.DeleteByIdAsync(Object id)

   --- End of inner exception stack trace ---

   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)

   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)

   at System.Threading.Tasks.Task`1.get_Result()


源码如下:

 [HttpPost, Route("delete")]

        public async Task<IActionResult> Delete([FromForm] string id)

        {

            if (string.IsNullOrEmpty(id))

            {

                return Fail("ID 不能为空");

            }


            return Result(await _printTemplateService.DeleteByIdAsync(id));

        }


热忱回答4

  • 看一下initkey是不是配置的attribute,在看一下实体是不是配有主键

    0 回复
  • SimpleClient.DeleteByIdAsync 这个方法确实有问题你先用

            public virtual async Task<bool> DeleteByIdsAsync(dynamic[] ids) 先用这个代替

    0 回复
  • liftlei liftlei VIP0
    2020/12/18

    @fate stay night:大佬,都没错

    =============================

     var config = new ConnectionConfig()

                {

                    ConnectionString = _options.DefaultConnection,

                    DbType = dbType,

                    IsAutoCloseConnection = true,

                    ConfigureExternalServices = new ConfigureExternalServices()

                    {

                        DataInfoCacheService = cacheService

                    },

                    MoreSettings = new ConnMoreSettings()

                    {

                        IsAutoRemoveDataCache = true,

                        DefaultCacheDurationInSeconds = 1800

                    },

                    InitKeyType = InitKeyType.Attribute

                };

    ====================================

    [SugarTable("print_template")]

        public class PrintTemplate

        {

            [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]

            public int Id { get; set; }


    0 回复
  • liftlei liftlei VIP0
    2020/12/18

    现在改成这样用:

    [HttpPost, Route("delete")]

            public async Task<IActionResult> Delete(PrintTemplate model)

            {

                if (model == null)

                {

                    return Fail("参数不能为空");

                }


                return Result(await _printTemplateService.DeleteAsync(model));

            }


    0 回复