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

  • Home
  • SEARCH
  • 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 6572007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:57:10+00:00 2026-05-25T14:57:10+00:00

I have generated classes (DbContext) modelling my db (SQL Server 2008 R2), and in

  • 0

I have generated classes (DbContext) modelling my db (SQL Server 2008 R2), and in most of my tables I have the standard ModifiedDate and CreatedDate (No Nulls). Each of these has a default of getdate() in SQLServer, and I have a trigger to update ModifiedDate on any updates.

The generated views included the ModifiedDate and CreatedDate fields, which I don’t want (the user shouldn’t see these), so I’ve taken these out, but when adding a new entry using the generated Create view, I get the error “The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value”.

I then added some default values, and it did add the record, but naturally it added my entered values, and not the SQL getdate() values, which I’d prefer (I want it to show the server time). Checking the object (db.SaveChanges()) the fields have a value of {1/01/0001 12:00:00 AM}.

How can I use these models without entering dates??? I’ve searched but haven’t found my answer… ;-(

  • 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-05-25T14:57:10+00:00Added an answer on May 25, 2026 at 2:57 pm

    This is a common problem in both Entity Framework and Linq to SQL:

    In Linq-To-SQL the model doesn’t know about the default values, and so attempts to assign them as “null” – which in this case isn’t acceptable. To fix this, open the DBML file and set the “Auto Generated Value” option to “true” for the fields in question.

    In Entity Framework it’s a little different: you set the “StoreGeneratedPattern” on the field to either “Identity” or “Computed”. Here’s the description:

    http://msdn.microsoft.com/en-us/library/system.data.metadata.edm.storegeneratedpattern.aspx

    EF will do this automatically for Identity type fields, but not for default value/not null fields. You may want to set your CreatedDate as “Identity” (updated only on insert) and your ModifiedDate as “Computed” (updated on insert and update).

    The byproduct of this is that you then will not be able to set the fields via Linq at all – but that’s fine in your use case, I think.

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

Sidebar

Related Questions

I have recursive stored procedure on SQL Server. I'm using Linq-to-SQL generated classes, and
I am using EF4.1, have upgraded my project, generated POCO classes to use DbContext
I have generated few classes using to LINQ to SQL one of them being
I have two classes generated by LINQ2SQL both from the same table so they
I have a post-compilation step that manipulates the Java bytecode of generated classes. I'd
I have a .dbml file which of course contains the auto-generated classes based on
I'm having trouble grasping generic methods. I have two classes that are generated (they
I'm using .NET 3.5. We have some complex third-party classes which are automatically generated
I'm using ASP.NET MVC RC2. I have a set of classes that were auto-generated
I have generated entity framework designer classes . After Generating the designer what is

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.