I have an entity framework model generated from database. One of the entities is 'Session' with 'Type' int property.
Auto-generated class:
public class Session
{
int Type { get; set;}
}
Edmx:
<EntityType Name="Sessions">
<Property Name="Type" Type="int" Nullable="false" />
</EntityType>
Sometimes when loading database values, I get an exception saying that it cannot set the 'Type' property (which is int) to a 'string' value:
System.InvalidOperationException: The 'Type' property on 'Session' could not be set to a 'System.String' value. You must set this property to a non-null value of type 'System.Int32'. at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader
1.GetValue(DbDataReader reader, Int32 ordinal) at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.GetPropertyValueWithErrorHandling[TProperty](Int32 ordinal, String propertyName, String typeName) at lambda_method(Closure , Shaper ) at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly[TEntity](Func
2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet) at lambda_method(Closure , Shaper ) at System.Data.Entity.Core.Common.Internal.Materialization.Coordinator1.ReadNextElement(Shaper shaper) at System.Data.Entity.Core.Common.Internal.Materialization.Shaper
1.SimpleEnumerator.MoveNext() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable1 source) at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable
1 source)
This is the query where it fails:
var session = db.Sessions.Include("Game.Mod").Where(s => s.UniqueId == message.SessionUid && s.DomainId == this.DomainId && s.Game.UniqueId == message.GameUid).FirstOrDefault();
When debugging locally, all is ok. This is when deployed to prod.
I'm currently using EF 6.1 on sql azure and I think it might be something to do with the upgrade, I don't think this was happening before (using 6.1). But I might be wrong.
Database column is also an int (100% confirmed), the mapping is correct.