There is an int ID column in a MS SQL database table, but the entity class contains a long ID field, and I get the following message in the context:
"An exception occured while reading a database value. The expected type was 'System.Int64' but the actual value was of type 'System.Int32'."
I've already tried to set the column type:
modelBuilder.Entity<XXXEntity>()
.Property(b => b.Id)
.HasColumnName("XXXId")
.HasColumnType("int");
but that does not work. What's the right solution?
I cannot change neither the entity class nor the db table.
Convert.ToInt32(myLongIdField). But there is valid reason why the program doesn't allow you to insert long into int type column. use this only if you are very sure that your "long" data will not be too big.