Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8655257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:59:01+00:00 2026-06-12T14:59:01+00:00

I am working on an Entity Framework project using SQL Server 2008. We recently

  • 0

I am working on an Entity Framework project using SQL Server 2008. We recently changed to use the datetime2 field type for a lot of our Dates as we need the precision.

This works fine against our live and development databases, but as part of our end-to-end tests we have been using SQL Server CE 4.0, which doesn’t support the datetime2 type. The moment Entity Framework tries to construct the database it returns a series of exceptions like this:

error 0040: The Type datetime2 is not qualified with a namespace or alias. Only primitive types can be used without qualification.

Obviously, there is no value in changing our production code for test purposes, so is there a way to tell it to convert the datetime2 values to a regular datetime or converting them to a varchar?

The purpose of the test is to ensure that everything from the data layer up to the interface is working as expected, so if there is a better way to implement this kind of test that might provide a useful alternative.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:59:02+00:00Added an answer on June 12, 2026 at 2:59 pm

    In the end I found a solution to this problem that works sufficiently for the end-to-end testing configuration I am working with. The solution I went for was to use a special DataContext to handle Sql Server CE requests, thus:

    public class TestDataContext : DataContext 
    {
    
        protected override void  OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
        {
            // list of available Conventions: http://msdn.microsoft.com/en-us/library/system.data.entity.modelconfiguration.conventions(v=vs.103).aspx 
    
            // Remove the column attributes that cause the datetime2 errors, so that 
            // for SQL Server CE we just have regular DateTime objects rather than using
            // the attribute value from the entity.
            modelBuilder.Conventions.Remove<ColumnAttributeConvention>();
    
            // Attempt to add back the String Length restrictions on the entities. I havent 
            // tested that this works.
            modelBuilder.Configurations.Add( new ComplexTypeConfiguration<StringLengthAttributeConvention>());
    
            // SQL Server CE is very sensitive to potential circular cascade deletion problems
            modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
    
        }
    
    }
    

    By replacing the regular DataContext with a TestDataContext in my test classes I have the same behaviour without SQL Server CE crashing out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on ASP.Net MVC3 web-site with Entity Framework and SQL Server 2008 as
I'm working on my first project, using Entity Framework. I've got a SQL Express
Working on a project using Entity Framework (4.3.1.0). I'm trying to figure out how
I'm changing my project from working with Linq-to-SQL to working with Entity Framework. I
I am using the Entity Framework and SQL Server Compact Edition through the code
Im working on a MVC3 project using code first entity framework. On a webpage
So I have been working on a project using Entity Framework 5 in development
I'm working on a project using WPF and MVVM with Entity Framework 4.3, and
I am working on a web application project and I am using Entity Framework
The setup: (using Asp.Net MVC 2 RC, Entity Framework, SQL Server, VS2008) My buddy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.