Я работаю над собственным проектом, для которого использую .NET Core 3.1 и инструмент ORM Linq2b. У меня проблема со вставкой данных с помощью асинхронного метода. Я хочу вставить данные журнала. В Linq2Db есть метод InsertWithInt32IdentityAsync. Этот метод возвращает ошибку:
Невозможно получить доступ к удаленному объекту. Имя объекта: IServiceProvider.
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()
Я работаю над собственным проектом, для которого использую .NET Core 3.1 и инструмент ORM Linq2b. У меня проблема со вставкой данных с помощью асинхронного метода. Я хочу вставить данные журнала. В Linq2Db есть метод InsertWithInt32IdentityAsync. Этот метод возвращает ошибку:
Невозможно получить доступ к удаленному объекту. Имя объекта: IServiceProvider.
Вот реализации. [code] [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 log; } [/code] Вот метод BaseDataProvider [b]InsertEntityAsync[/b]. [code] public virtual async Task InsertEntityAsync(TEntity entity) where TEntity : BaseEntity { using var dataContext = CreateDataConnection(); entity.Id = await dataContext.InsertWithInt32IdentityAsync(entity); return entity; } [/code] Вот StackTrace. [code] 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() [/code] [img]https://i.sstatic.net/Y8tAC.png[/img]