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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:37:29+00:00 2026-05-31T17:37:29+00:00

I have a Candidate entity, with some associations exampled below. I have a view

  • 0

I have a Candidate entity, with some associations exampled below. I have a view model that doesn’t have the reference properties, just the foreign key properties, and I am using AutoMapper to map the view model back to an entity. When I try and save the entity, I get validation errors telling me that e.g. The Title field is required. because although my TitleId has a valid value, Title is still null.

public class Candidate
{
...
    [Required]
    public string RefNum { get; set; }

    [ForeignKey("TitleId")]
    [Required]
    public Title Title { get; set; }
    public Guid TitleId { get; set; }
...
}

PS, I can see how the Required attribute is causing trouble here, but how else do I insist that TitleId must be a valid ID, not just an empty Guid?

  • 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-31T17:37:30+00:00Added an answer on May 31, 2026 at 5:37 pm

    Remove the [Required] attribute. It doesn’t guarantee anyway that your Guid is not empty because an empty Guid {00000000-0000-0000-0000-000000000000} is a valid Guid which is a valid uniqueidentifier column value in the database. (Guid is a struct which cannot be null.) You are responsible to set the correct value of the Guid. Because the Guid is not nullable EF will detect the relationship as required anyway.

    Alternatively you can also turn off the validation for the context instance…

    context.Configuration.ValidateOnSaveEnabled = false;
    

    …to avoid the error. You can also configure the mapping in Fluent API (HasRequired/WithRequired) instead of using the data annotation to avoid the validation error.

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

Sidebar

Related Questions

I have some customers/candidate who complained that my program doesn't work on their Windows
I need to have an entity that has two separate candidate keys where one
I have the following on my edit screen: <label for=campaign.CandidateID>Candidate:</label> <%= Html.DropDownList(Campaign.CandidateID, Model.Candidates, Choose...)%>
I have an ASP.NET MVC (using the release candidate) application that works with a
I have a merge candidate that i cannot merge to a branch from source
I have a Candidades class that holds Candidate objects, as follow: import java.util.*; public
I have a query in MySQL that returns three columns, a Candidate's ID, the
I have a pending project that may or may not be a good candidate
I have a data storage requirement which is an excellent candidate for single instance
I have this piece of code: <li class=selected><a href=/AmIACandidate.html>Am I a Candidate?</a></li> I need

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.