MikaelEliasson / EntityFramework.Utilities

Provides extensions for EntityFramework that doesn't exist out of the box like delete and update by query and bulk inserts
443 stars 175 forks source link

The given ColumnMapping does not match up with any column in the source or destination #121

Open americanslon opened 6 years ago

americanslon commented 6 years ago

In my project I use bulk insert on five different entities in the same. 4 work , while the 5th one fails with the above error. I don't even know where to start debugging this, as the above error is all I get.

This is a code first EF 6.2.0 application.

This is how I use it List<Rule> list = new List<Rule>(); ... EFBatchOperation.For(context, context.Rules).InsertAll(list);

DEV-MAX commented 3 years ago

any update on above?. One of the column in entity is different from table and fluent map exist in solution.

DEV-MAX commented 3 years ago

I managed to fix this by using the property mapping. I've updated the column name.

var m = EfMappingFactory.GetMappingsForContext(this.contextx as DbContext).TypeMappings[typeof(Customer)];
                var table = m.TableMappings.First();
                table.PropertyMappings.ForEach(property =>
                {
                    if (property.PropertyName == "Id")
                    {
                        property.ColumnName = "ID";
                    }
                });
RudeySH commented 3 years ago

@DEV-MAX It sounds like the casing of the ID column in the database does not match with the casing of the Id column in your EF model. Unless you are using [Column("ID")] or HasColumnName("ID") to configure this discrepancy in your EF model, EFUtilities is not going to be able to properly map your entities.

DEV-MAX commented 3 years ago

@DEV-MAX It sounds like the casing of the ID column in the database does not match with the casing of the Id column in your EF model. Unless you are using [Column("ID")] or HasColumnName("ID") to configure this discrepancy in your EF model, EFUtilities is not going to be able to properly map your entities.

Yeah, EF is case insensitive when it comes to column name, so I didn't defined the column mapping initially. Now I defined the HasColumnName and it's working . Thank you