How do I resolve issues with unsupported DateTimeOffsets in EF 6 using Sql Server?

.net c# datetimeoffset entity-framework-6


I obtain the following notice when I attempt to instantiate a DbContext:

System.NotSupportedException: There is no store type corresponding to the conceptual side type 'DateTimeOffset' of primitive type 'DateTimeOffset'.

On SQL Server, I'm using Entity Framework version 6.

The architect of theDbContext Looks like this (with the line that throws the exception)

    internal TestHubContext(string connectionStringName) : base(connectionStringName)
        var objectContext = (this as IObjectContextAdapter).ObjectContext;


The entities are made using code first and have the following appearance:

public class Order
    public System.Guid Id { get; set; }

    public string CreatedBy { get; set; }

    public System.DateTimeOffset CreatedUtcDate { get; set; }

The database migrations went smoothly and produced the following table:

CREATE TABLE [dbo].[Orders](
[Id] [uniqueidentifier] NOT NULL,   
[CreatedBy] [nvarchar](60) NOT NULL,
[CreatedUtcDate] [datetimeoffset](7) NOT NULL,  

Therefore, both the database and the C# code contain the necessary data types. I'm not really sure why this is taking place.

The stack trace I'm receiving looks like this:

at System.Data.Entity.SqlServer.SqlProviderManifest.GetStorePrimitiveTypeIfPostSql9(String storeTypeName, String nameForException, PrimitiveTypeKind primitiveTypeKind) at System.Data.Entity.SqlServer.SqlProviderManifest.GetStoreType(TypeUsage edmType) at System.Data.Entity.ModelConfiguration.Edm.Services.StructuralTypeMappingGenerator.MapTableColumn(EdmProperty property, String columnName, Boolean isInstancePropertyOnDerivedType) at System.Data.Entity.ModelConfiguration.Edm.Services.PropertyMappingGenerator.Generate(EntityType entityType, IEnumerable1 properties, EntitySetMapping entitySetMapping, MappingFragment entityTypeMappingFragment, IList1 propertyPath, Boolean createNewColumn) at System.Data.Entity.ModelConfiguration.Edm.Services.TableMappingGenerator.Generate(EntityType entityType, DbDatabaseMapping databaseMapping) at System.Data.Entity.ModelConfiguration.Edm.Services.DatabaseMappingGenerator.GenerateEntityTypes(DbDatabaseMapping databaseMapping) at System.Data.Entity.ModelConfiguration.Edm.Services.DatabaseMappingGenerator.Generate(EdmModel conceptualModel) at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo) at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeContext() at System.Data.Entity.Internal.InternalContext.ForceOSpaceLoadingForKnownEntityTypes() at System.Data.Entity.DbContext.System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext()

Any suggestions for how to overcome this issue without breaking the datatypes would be greatly appreciated.

3/11/2015 4:33:28 PM

Accepted Answer

Facepalm! An error in the connection string's name in the configuration file led to this problem.

The issue vanished as soon as I verified that the connection string's name in the configuration matched the one given to the DbContext.

Of course, the exception that was made did not help me.

I'm providing this as a response in the hopes that someone else will find it in the future or, at the very least, be aware that this kind of exception can be made in a number of circumstances.

3/13/2015 11:24:52 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow