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 508803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:56:43+00:00 2026-05-13T06:56:43+00:00

I am using Entity Framework with asp.net mvc, but I don’t think mvc plays

  • 0

I am using Entity Framework with asp.net mvc, but I don’t think mvc plays a big role here.

I have an object Customer, and a lookup table (there are several, and they all behave the same way; so for simplicity I’ll pick Territory). Both Customer and Territory have LastUpdated field (Datetime that is set manually in the code).

If I hardcode Territory, and get only Customer data from the View, I don’t have any problems:

public ActionResult CreateCustomer([Bind(Exclude = "CustId")] Customer cm) {
    cm.Territory = (from t in repo.Territory where t.ID == 2 select t).First();
    repo.AddToCustomer(cm);
    repo.SaveChanges();
}

As I said, no problems. However, if I use a dropdown in the view with the matching id (Territory.ID) – there is a problem. I have the following line in controller:

ViewData["territory"] = new SelectList(repo.Territory, "ID", "Name", 1);

and corresponding line in the View:

Territory: <%= Html.DropDownList("Territory.ID", (IEnumerable<SelectListItem>)ViewData["territory"])%>

I get good news and bad news: the good news is that I get the territory ID nicely assigned to the appropriate member of Customer object. The bad news is that Territory.LastUpdated value is set to 1/01/0001. Obviously, I don’t care about this value – but it looks like EF cares. When I call SaveChanges I am getting the following error:

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM

Looks like EF is trying to retrieve the value from the database, and then compare it with EF value… or maybe something else – but the bottom line is I can’t figure out how to prevent it from trying to be so smart.

For now, I name DropDown ID to be something different (“terID” instead of “Territory.ID”), and using FormCollection:

int terID = Int32.Parse(formData["terID"]);
cm.Territory = (from d in repo.Territory
     where d.ID == terID select d).First();

This works (which makes me comfortable with my analysis) but this cannot be the best way.
I also can’t believe that nobody bumped into such problem – but I couldn’t find anything relevant… The best I could find is link text but it’s more of a hint without much details

I tried to cut out all unrelated stuff from the code – so if there are some typos, they are in the post; not necessarily in the code itself!
Thanks

  • 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-13T06:56:43+00:00Added an answer on May 13, 2026 at 6:56 am

    I’m assuming you are using EF 1.0 which is not good at direct foreign key maping.

    Territory posted from view to action is not bound to Datacontext, hence when you save your customer object – EF saves attached Territory Object as well.

    You have to get Territory object from db first and then assign it to customer.

    And Your solution is perfectly fine, cos there is no other for EF 1.0 )-:

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

Sidebar

Ask A Question

Stats

  • Questions 262k
  • Answers 262k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can do it using Rhino 1.6R6 or higher with… May 13, 2026 at 11:50 am
  • Editorial Team
    Editorial Team added an answer You can do this if you add each control to… May 13, 2026 at 11:50 am
  • Editorial Team
    Editorial Team added an answer Ah figured it out on my own. In the design… May 13, 2026 at 11:50 am

Related Questions

I am using the Ado.Net Entity Framework with ASP.NET MVC. In my MSSQL 2008
I have a field of type image in my database which is mapped as
Are there any open-source examples of ASP.NET MVC applications that use the Entity Framework?
I have built a MVC website on IIS6. I used the built-in ASP.NET Security
Quick questions really. I am currently building a site using asp.net MVC and the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.