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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:03:21+00:00 2026-06-06T19:03:21+00:00

With the following DB schema: CREATE TABLE master ( id integer primary key autoincrement,

  • 0

With the following DB schema:

CREATE TABLE master (
    id integer primary key autoincrement, 
    title text);
CREATE TABLE slave (
    id integer primary key autoincrement, 
    master_id integer not null, 
    title text, 
    foreign key (master_id) references master (id));

I created an sqlite database, which I then used to create an Entity Framework .edmx file.

Then I add a master and a slave record, which works fine, and then I try to remove the slave record, but that raises an exception and I don’t know why.

var ctx = new blaEntities();
var newMaster = master.Createmaster(0);
ctx.masters.AddObject(newMaster);

var newSlave = slave.Createslave(0, 0);
newMaster.slaves.Add(newSlave);

ctx.SaveChanges(); // works fine, both id and master_id properties of newMaster 
                   // and newSlave are then set with generated values.

newMaster.slaves.Remove(newSlave);

ctx.SaveChanges(); // InvalidOperationException is raised

The message of the exception is:

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.

What am I doing wrong?

Edit:

Here is the generated by EF Createslave(...) method:

public static slave Createslave(global::System.Int64 id, global::System.Int64 master_id)
{
    slave slave = new slave();
    slave.id = id;
    slave.master_id = master_id;
    return slave;
}
  • 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-06T19:03:23+00:00Added an answer on June 6, 2026 at 7:03 pm

    There is still a slave object in your slave table that has no value set in the masterId column.

    Try using ctx.DeleteObject(newSlave) to get rid of it.

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

Sidebar

Related Questions

Given the following schema: CREATE TABLE players ( id BIGINT PRIMARY KEY, name TEXT
Please consider following schema CREATE table articles ( id Int UNSIGNED NOT NULL AUTO_INCREMENT,
Consider the following database schema: create table UserGroup ( id int not null auto_increment,
I have the following table schema: CREATE TABLE [Foo]( [id] [int] NOT NULL, [name]
Given the following (heavily simplified) tables: create table Tags ( TagId int Primary Key
I have got the following simplified schema: CREATE TABLE [file] ( id UNIQUEIDENTIFIER NOT
Say I have a table with the following schema: CREATE TABLE tasks (taskID TEXT,
I have a table with the following schema: CREATE TABLE table ( msg_id TEXT,
I have two tables with the following schema: CREATE TABLE sales_data ( sales_time date
I have a DB table that uses the following schema: CREATE TABLE users (id

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.