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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:41:50+00:00 2026-06-07T13:41:50+00:00

I have a VERY simple model as seen here: public class Cases { //case

  • 0

I have a VERY simple model as seen here:

public class Cases
    {
    //case data model for call center
    //implement lists for all related child tables too

    [Key]
    public int CasesID { get; set; }

    public string CaseNumber { get; set; }

    [Required(ErrorMessage = "Customer is Required")]
    public int CustomerID { get; set; }
    public Customer Customer { get; set; }

    [MaxLength(50)]
    public string UserName { get; set; }  //get user name from the aspnet membership

    [Required(ErrorMessage = "Case Category is Required")]
    public int CaseCategoryID { get; set; }

    [Required(ErrorMessage = "Technician is Required")]
    public int TechnicianID { get; set; }
    public Technician Technicians { get; set; }

    [Required(ErrorMessage = "Engine Model is Required")]
    public int EngineModelID { get; set; }
    public EngineModel EngineModel { get; set; }

    [MaxLength(50)]
    public string BMSWorkorder { get; set; }

    [MaxLength(50)]
    [Required(ErrorMessage = "Status is Required")]
    public string CaseStatus { get; set; }

    [MaxLength(50)]
    public string OpenedBy { get; set; }

    [Required(ErrorMessage = "Opened Date is Required")]
    [DataType(DataType.DateTime)]
    public DateTime? OpenedDate { get; set; }

    [MaxLength(50)]
    public string ClosedBy { get; set; }

    [DataType(DataType.DateTime)]
    public DateTime? ClosedDate { get; set; }

    [MaxLength(50)]
    [Required(ErrorMessage="Caller First Name is Required")]
    public string CallerFirstName { get; set; }

    [MaxLength(50)]
    [Required(ErrorMessage = "Caller Last Name is Required")]
    public string CallerLastName { get; set; }

    [MaxLength(10)]
    [Required(ErrorMessage = "Qualified is Required")]
    public string Qualified { get; set; }

    public string Description { get; set; }

    [MaxLength(50)]
    [Required(ErrorMessage = "ESN is Required")]
    public string ESN { get; set; }

    [MaxLength(50)]
    [Required(ErrorMessage = "Mileage is Required")]
    public string Mileage { get; set; }

    [DataType(DataType.Date)]
    public DateTime? DateInService { get; set; }

    [MaxLength(50)]
    public string ESTR { get; set; }

    [MaxLength(50)]
    [Required(ErrorMessage = "EDS is Required")]
    public string EDS { get; set; }

    [MaxLength(50)]
    public string GensetSerialNumber { get; set; }

    [MaxLength(50)]
    public string GensetModelNumber { get; set; }

    //child Case Notes records
    public virtual ICollection<CaseNotes> CaseNotes { get; set; }

    //child case attachment records
    public virtual ICollection<Attachment> Attachments { get; set; }

    //child case complaint records
    public virtual ICollection<CaseComplaint> CaseComplaint { get; set; }

    //tracking fields
    public DateTime? CreatedOn { get; set; }
    [MaxLength(50)]
    public string CreatedBy { get; set; }
    public DateTime? ModifiedOn { get; set; }
    [MaxLength(50)]
    public string ModifiedBy { get; set; }
    }

A Case can have many CaseNotes, Attachments, and CaseComplaints. Foreign Keys are Technicians, Customers, and EngineModel.

Up until today, all was well with Add, and Edits with this model. Now, out of the blue I get
“A referential integrity constraint violation occurred: The property values that define the referential constraints are not consistent between principal and dependent objects in the relationship.”
only when trying to update a case record on the Edit view. A create and insert is fine since all required fields are filled.
Why would this just start happening. FYI, If I inspect the model just be for I call context.SaveChanges, I notice that all the data looks right, FK values are filled in, however the data in the navigation property for the foreign key class (Technicians) almost seems like it thinks I am trying to insert a new record in those classes…

Here are my controller Edit actions:

public ActionResult Edit(int id)
    {
        Cases cases = db.Cases.Find(id);
        db.Entry(cases).Reference(x => x.Customer).Load();
        db.Entry(cases).Collection(x => x.CaseComplaint).Load();
        db.Entry(cases).Collection(x => x.CaseNotes).Load();
        db.Entry(cases).Reference(x => x.Technicians).Load();

        GetCaseCategoryLookup(cases.CaseCategoryID);
        GetEngineModelLookup(cases.EngineModelID);
        GetTechnicianLookup(cases.TechnicianID);
        GetQualifiedList(cases.Qualified);
        GetCaseStatusList(cases.CaseStatus);

        return View(cases);
    }

    //
    // POST: /Cases/Edit/5

    [HttpPost]
    public ActionResult Edit(Cases cases)
    {
        if (ModelState.IsValid)
        {
        AppHelpers help = new AppHelpers();

            if (cases.CaseStatus == "CLOSED")
                {
                cases.ClosedBy = "USER";
                cases.ClosedDate = help.GetEasternTime();
                }
            cases.ModifiedBy = "USER";
            cases.ModifiedOn = help.GetEasternTime();

            db.Entry(cases).State = EntityState.Modified;
            db.SaveChanges();

        }

        return RedirectToAction("Index");
    }
  • 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-07T13:42:00+00:00Added an answer on June 7, 2026 at 1:42 pm

    Just to explain what the exception means:

    A referential integrity constraint violation occurred: The property
    values that define the referential constraints are not consistent
    between principal and dependent objects in the relationship.

    Principal object in your controller post action is cases.Technicians, the dependent is cases. The “property values that define the referential constraints” are the foreign key in the dependent object, that is cases.TechnicianID, and on the other side the primary key of the principal, that is cases.Technicians.TechnicianID.

    The exception says that those two values are different: cases.TechnicianID != cases.Technicians.TechnicianID but they must be the same when you update the entity.

    I don’t know what your view is exactly supposed to do. Can you only edit the cases entity or also the cases.Technicians properties? Or can you only assign a new existing technician to cases? If the latter is the case I’m worndering why the model binder creates a cases.Technicians instance because there shouldn’t be any form fields that hold properties of the cases.Technicians. To assign another existing technician it should be enough to have the foreign key cases.TechnicianID bound to a form field.

    In any case you need to ensure that either cases.TechnicianID and cases.Technicians.TechnicianID have the same value or that cases.Technicians is null. It depends on what the view is supposed to do and what data you need to update – only cases properties or cases.Technicians properties as well.

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

Sidebar

Related Questions

I have a very simple composite model made of two classes: Public Class ParentModelVM
I have a public class called Profile . Very simple model class currently with
I have a very simple object model with a base class Person and two
I have a very simple issue: User model: class User < ActiveRecord::Base devise :database_authenticatable,
I have very simple data model like this: create table Company ( id int
Supose we have a very simple model: Station has at least one Train Train
I have a very simple model that includes the auto-filled field much like 'created'.
I have a very simple model with two objects: Name and Category. One Name
I have very simple backbone model and collection. I have a corresponding backbone.marionette.CollectionView and
I have a very simple user model. When I first created it, it had

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.