InvalidCastException on bulk insert
Hi,
Using the Nuget package EntityFramework6.BulkInsert, I'm trying to insert a collection of 200-300 items into a table and failing with the following exception:
System.InvalidCastException: 'Specified cast is not valid.' Stack Trace: at EntityFramework.MappingAPI.Mappers.MapperBase.MapProperty(EntityMap entityMap, EdmProperty edmProperty, Int32& i, String& prefix)
The C# call is as follows: ctx.BulkInsert<DSearch>(ds, ctx.Database.CurrentTransaction?.UnderlyingTransaction); where ctx is a DbContext instance. There is an underlying transaction.
The table structure DSearch is simple:
public class DSearch
{
public Guid Id { get; set; }
public string Match { get; set; }
public int Distance { get; set; }
public int Index { get; set; }
}
Worth mentioning is that the PK on that table is composite, formed of all 4 properties/columns.
Hi,
Do you have a reproducible project you can upload to help troubleshoot the exact issue? It can be as simple as a code first repo of the structure, or a script for creating the exact table structure and solution for inserting.