EFCore.BulkExtensions无法使用Guid PK

时间:2019-07-05 12:40:22

标签: entity-framework ef-code-first sqlbulkcopy ef-core-2.2

我正在使用EFCore.BulkExtensions将具有GUID / UniqueIdentifier主键的实体插入我的数据库,但是当我调用此行时收到以下异常:

  

System.InvalidOperationException HResult = 0x80131509 Message =   来自数据源的String类型的给定值无法转换为   输入指定目标列的uniqueidentifier。
  来源= EFCore.BulkExtensions StackTrace:位于   EFCore.BulkExtensions.SqlBulkOperation.Insert [T](DbContext上下文,   IList 1 entities, TableInfo tableInfo, Action 1个进度)   EFCore.BulkExtensions.DbContextBulkExtensions.BulkInsert [T](DbContext   上下文,IList 1 entities, BulkConfig bulkConfig, Action 1个进度)
  在   MyCompany.Abp.EfCore.BulkExtensions.BulkInsert [TEntity,TPrimaryKey](IRepository 2 repository, IList 1个实体,BulkConfig bulkConfig,Action 1 progress) in D:\Projects\MySystem\Utilities\MyCompany.Abp.EfCore\BulkExtensions.BulkInsert.cs:line 21 at s.SearchServices.Infrastructure.UnscConsolidatedList.Infrastructure.s.MonitoringBatch.MonitoringBatchSearchJob.PerformScreening(Guid sourceId, IList 1个记录)   D:\ Projects \ MySystem \ Modules \ s \ s.SearchServices.Infrastructure.UnscConsolidatedList \ Infrastructure \ s \ MonitoringBatch \ MonitoringBatchSearchJob.cs:line   96时   s.SearchServices.Infrastructure.UnscConsolidatedList.Infrastructure.s.MonitoringBatch.MonitoringBatchSearchJob.ExecuteJob(MonitoringBatchSearhJobArgs   args)在   D:\ Projects \ MySystem \ Modules \ s \ s.SearchServices.Infrastructure.UnscConsolidatedList \ Infrastructure \ s \ MonitoringBatch \ MonitoringBatchSearchJob.cs:line   82点   s.SearchServices.Infrastructure.UnscConsolidatedList.Core.BatchSearchJobBase`1.Execute(TBatchSearhJobArgs   args)在   D:\ Projects \ MySystem \ Modules \ s \ s.SearchServices.Infrastructure.UnscConsolidatedList \ Core \ BatchSearchJobBase.cs:line   28

     

内部异常1:InvalidCastException:无法转换参数   值从字符串到Guid。

     

内部异常2:InvalidCastException:无效的强制转换自   “ System.String”到“ System.Guid”。

引发异常的代码:

        public static void BulkInsert<TEntity, TPrimaryKey>(
            this IRepository<TEntity, TPrimaryKey> repository,
            IList<TEntity> entities,
            BulkConfig bulkConfig = null,
            Action<decimal> progress = null)
            where TEntity : class, IEntity<TPrimaryKey>
        {
            var db = repository.GetDbContext();
            db.BulkInsert(entities, bulkConfig, progress); // <== throws exception
        }

我在做什么错了?

0 个答案:

没有答案