CSh*_*ark 5 entity-framework sqlbulkcopy ef-code-first ef-core-2.2
我正在使用 EFCore.BulkExtensions 将具有 GUID / UniqueIdentifier 主键的实体插入到我的数据库中,但当我调用此行时,我收到以下异常:
System.InvalidOperationException HResult=0x80131509 Message=来自数据源的 String 类型的给定值无法转换为指定目标列的 uniqueidentifier 类型。
源 = EFCore.BulkExtensions StackTrace:在 EFCore.BulkExtensions.SqlBulkOperation.Insert[T](DbContext 上下文,IList1 entities, TableInfo tableInfo, Action1 进度)在 EFCore.BulkExtensions.DbContextBulkExtensions.BulkInsert[T](DbContext 上下文,IList1 entities, BulkConfig bulkConfig, Action1 进度)
在 MyCompany.Abp。D:\Projects\MySystem\Modules\s\s.SearchServices.Infrastruct.UnscConsolidatedList\Infrastruct\s\MonitoringBatch\MonitoringBatchSearchJob 中的EfCore.BulkExtensions.BulkInsert[TEntity、TPrimaryKey](IRepository2 repository, IList1 实体、BulkConfigbulkConfig、操作1 记录)。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, IListcs:第 96 行位于 D:\Projects\MySystem\Modules\s\s.SearchServices.Infrastruct.UnscConsolidatedList\Infrastruct\s\ 中的 s.SearchServices.Infrastruct.UnscConsolidatedList.Infrastruct.s.MonitoringBatch.MonitoringBatchSearchJob.ExecuteJob(MonitoringBatchSearhJobArgs args) MonitoringBatch\MonitoringBatchSearchJob.cs:第 82 行位于 s.SearchServices.Infrastruct.UnscConsolidatedList.Core.BatchSearchJobBase`1.Execute(TBatchSearhJobArgs args),位于 D:\Projects\MySystem\Modules\s\s.SearchServices.Infrastruct.UnscConsolidatedList\Core\ BatchSearchJobBase.cs:第 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
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
| 归档时间: |
|
| 查看次数: |
864 次 |
| 最近记录: |