none
How to set the ProviderManifestToken with EF Code First? RRS feed

  • Question

  • This doesn't seem like a complicated question, but having spent the last 30 minutes browsing through the entity framework source in my decompiler of choice (please don't sue me Microsoft, I only use it to understand the awesome ideas you have), I'm starting to think it might be a little more difficult.

    I have the same problem as a lot of people with Sql Server versions and datetime2.  My issue is that I'm developing locally against a SQL 2012 express instance, but I'm deploying to a hosting provider who (and I didn't realise this until it just failed) is apparently stuck in the past with a SQL 2005 instance they clearly can't be bothered to upgrade.

    My problem is that I would like to manually force the ProviderManifestToken value to 2005 so I can guarentee my code works fine in both environments.  I know that when I deploy, and it builds the database it will check the version there and generate a schema for SQL 2005, but then I may get issues with date time values being out of range, which i won't see locally (because EF so cleverly set it's compatibilty to 2012, or more likely 2008 (don't know if there's a manifest value for 2012 yet)).

    You can set it in the EDMX so can you set it in Code First, or through the configuration section in web.config? And if so how??

    Thanks.

    Monday, June 25, 2012 8:51 PM

Answers

  • Hi Murphy,

    Welcome to MSDN Forum.

    I suggest you to specify the type of the column in the 'OnModelCreating' method, for example:

    modelBuilder.Entity<Blog>().Property(t => t.CreatedOn).HasColumnName("CreatedOn").HasColumnType("date");

    Best Regards

    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, June 27, 2012 6:11 AM
    Moderator