Асинхронная вставка Linq2Db — невозможно получить доступ к удаленному объекту. ObjectDispose_ObjectName_Name'C#

Место общения программистов C#
Ответить
Anonymous
 Асинхронная вставка Linq2Db — невозможно получить доступ к удаленному объекту. ObjectDispose_ObjectName_Name'

Сообщение Anonymous »

Я работаю над собственным проектом, для которого использую .NET Core 3.1 и инструмент ORM Linq2b. У меня проблема со вставкой данных с помощью асинхронного метода. Я хочу вставить данные журнала. В Linq2Db есть метод InsertWithInt32IdentityAsync. Этот метод возвращает ошибку:

Невозможно получить доступ к удаленному объекту. Имя объекта: IServiceProvider.

Вот реализации.

Код: Выделить всё

    [HttpPost("createpost")]
[Authorize]
public virtual async Task CreatePost([FromForm] PostCreateApi model)
{
var serviceResponse = _postService.Create(model);

if (serviceResponse.Warnings.Count > 0 || serviceResponse.Warnings.Any())
return BadResponse(new ResultModel
{
Status = false,
Message = serviceResponse.Warnings.First()
});

//Here returns an error
await _logService.InsertLogAsync(Domain.Enumerations.LogLevel.Information, $"PostsController- Create Post Request", JsonConvert.SerializeObject(model));

return OkResponse(new PostListDto
{
Id = serviceResponse.Data.Id,
Text = serviceResponse.Data?.Text,
ImageUrl = serviceResponse.Data.ImageUrl?.ToString(),
CreatedByUserName = serviceResponse.Data?.CreatedByUserName,
CreatedByUserPhoto = serviceResponse.Data?.CreatedByUserPhoto,
CreatedDate = serviceResponse.Data.CreatedDate,
VideoUrl = serviceResponse.Data?.VideoUrl,
PostType = serviceResponse.Data?.PostType,
Comments = null
});
}
Вот метод InsertLogAsync.

Код: Выделить всё

 public virtual async Task InsertLogAsync(LogLevel logLevel, string shortMessage, string fullMessage = "", AppUser appUser = null)
{
var log = new Log
{
LogLevel = logLevel,
ShortMessage = shortMessage,
FullMessage = fullMessage,
IpAddress = _webHelper.GetCurrentIpAddress(),
CustomerId = appUser?.Id,
PageUrl = _webHelper.GetThisPageUrl(true),
ReferrerUrl = _webHelper.GetUrlReferrer(),
CreatedDate = DateTime.UtcNow
};

await _logRepository.InsertAsync(log);

return log;
}
Вот метод BaseDataProvider InsertEntityAsync.

Код: Выделить всё

  public virtual async Task  InsertEntityAsync(TEntity entity) where TEntity :
BaseEntity
{
using var dataContext = CreateDataConnection();
entity.Id = await dataContext.InsertWithInt32IdentityAsync(entity);
return entity;
}
Вот StackTrace.

Код: Выделить всё

   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ThrowHelper.ThrowObjectDisposedException()
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
at FluentMigrator.Infrastructure.MigrationContext..ctor(IQuerySchema querySchema, IServiceProvider serviceProvider, Object context, String connection)
at DevPlatform.Data.Migrations.MigrationManager.CreateNullMigrationContext() in C:\Projects\DevPlatform\DevPlatform.Data\Migrations\MigrationManager.cs:line 165
at DevPlatform.Data.Migrations.MigrationManager.GetCreateTableExpression(Type type) in C:\Projects\DevPlatform\DevPlatform.Data\Migrations\MigrationManager.cs:line 240
at DevPlatform.Data.Mapping.FluentMigratorMetadataReader.c__DisplayClass2_0`1.b__1(Type entityType) in C:\Projects\DevPlatform\DevPlatform.Data\Mapping\FluentMigratorMetadataReader.cs:line 42
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at DevPlatform.Data.Mapping.FluentMigratorMetadataReader.c__DisplayClass2_0`1.b__0(ValueTuple`2 t) in C:\Projects\DevPlatform\DevPlatform.Data\Mapping\FluentMigratorMetadataReader.cs:line 42
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at DevPlatform.Data.Mapping.FluentMigratorMetadataReader.GetAttribute[T](Type type, MemberInfo memberInfo) in C:\Projects\DevPlatform\DevPlatform.Data\Mapping\FluentMigratorMetadataReader.cs:line 40
at DevPlatform.Data.Mapping.FluentMigratorMetadataReader.GetAttributes[T](Type type, Type attributeType, MemberInfo memberInfo) in C:\Projects\DevPlatform\DevPlatform.Data\Mapping\FluentMigratorMetadataReader.cs:line 76
at DevPlatform.Data.Mapping.FluentMigratorMetadataReader.GetAttributes[T](Type type, Boolean inherit) in C:\Projects\DevPlatform\DevPlatform.Data\Mapping\FluentMigratorMetadataReader.cs:line 97
at LinqToDB.Mapping.MappingSchema.c__DisplayClass51_0`1.b__0(IMetadataReader mr)
at System.Linq.Enumerable.d__181`3.MoveNext()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
at LinqToDB.Mapping.MappingSchema.GetAttributes[T](Type type, Boolean inherit)
at LinqToDB.Mapping.MappingSchema.GetAttributes[T](Type type, Func`2 configGetter, Boolean inherit, Boolean exactForConfiguration)
at LinqToDB.Mapping.MappingSchema.GetAttribute[T](Type type, Func`2 configGetter, Boolean inherit)
at LinqToDB.Mapping.EntityDescriptor.Init()
at LinqToDB.Mapping.EntityDescriptor..ctor(MappingSchema mappingSchema, Type type)
at LinqToDB.Mapping.MappingSchema.c.b__92_0(ICacheEntry o, f__AnonymousType131`2 key, MappingSchema context)
at LinqToDB.Common.Internal.Cache.CacheExtensions.GetOrCreate[TItem,TKey,TContext](IMemoryCache cache, TKey key, TContext context, Func`4 factory)
at LinqToDB.Mapping.MappingSchema.GetEntityDescriptor(Type type)
at LinqToDB.Linq.QueryRunner.GetType[T](T obj, IDataContext db)
at LinqToDB.Linq.QueryRunner.InsertWithIdentity`1.d__2.MoveNext()
Изображение

Изображение
Изображение

[img]https://i. sstatic.net/CJSgE.png[/img]


Подробнее здесь: https://stackoverflow.com/questions/668 ... -objectnam
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»