EntityFramework.BulkInsert icon indicating copy to clipboard operation
EntityFramework.BulkInsert copied to clipboard

InvalidCastException on bulk insert

Open v-echo opened this issue 6 years ago • 1 comments

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.

v-echo avatar Aug 27 '19 14:08 v-echo

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.

ghost1face avatar Sep 15 '19 15:09 ghost1face