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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:52:23+00:00 2026-06-05T01:52:23+00:00

Consider I have 2 entities – a) Publisher b) Book Publisher has navigation property

  • 0

Consider I have 2 entities – a) Publisher b) Book
Publisher has navigation property called as PublishedBooks which is collection of Books.
Assume that Publisher1 has published 2 books ie Book1 & Book2
What I would like to do is, for a Publisher1, delete published book Book1 and
add a new published book (ie Book3), in the database.

Context.SaveChanges() throwing below error –

The operation failed: The relationship could not be changed because
one or more of the foreign-key properties is non-nullable. When a
change is made to a relationship, the related foreign-key property is
set to a null value. If the foreign-key does not support null values,
a new relationship must be defined, the foreign-key property must be
assigned another non-null value, or the unrelated object must be
deleted.

Note : Delete cascade rule is present in database as well as in the context class.
BTW, I am using C# & Sql Server 2005.

  • 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-05T01:52:25+00:00Added an answer on June 5, 2026 at 1:52 am

    Sounds like you are doing something like this:

    Foo foo = entity.RelatedFoos.Where(f=>f.id=xyz);
    entity.RelatedFoos.Remove(foo); //this is the problematic line
    context.SaveChanges();
    

    That is; you are removing an entity from a set of related items – not from the main collection on the context itself. As noted in the error, removing the above way only removes the relation. Not the object foo. This is probably what you meant, if you mean to delete the foo:

    Foo foo = entity.RelatedFoos.Where(f=>f.id=xyz);
    context.Foos.Remove(foo);
    context.SaveChanges();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider I have this following model definition, I want a particular property which should
Consider the following scenario We have a simple database that involves two entities: user
Consider I have a game-creation framework, with a basic class called Game. // Action
Consider I have an array of elements out of which I want to create
Consider I have a table with notes which could be associated with zero or
Consider I have an anchor which looks like this <div class=res> <a href=~/Resumes/Resumes1271354404687.docx> ~/Resumes/Resumes1271354404687.docx
Consider that i have two entities with following relationship: Entity A <-->> Entity B
Consider I have some environment(let's name it world ) and some entities(let's name them
I have a question concerning Hibernate 3.6.7 and JPA 2.0. Consider following entities (some
Our company has 4 business entities, so I have created 4 different databases for

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.