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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:19:46+00:00 2026-05-26T23:19:46+00:00

This seems like the most common relationship but for some reason I cannot get

  • 0

This seems like the most common relationship but for some reason I cannot get code-first EF working. When I run the code below I get the following error:

*{“Introducing FOREIGN KEY constraint ‘Recording_RecordingLocation’ on table ‘Recordings’ may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.\r\nCould not create constraint. See previous errors.”}*

I have researched SO and other places but have not been able to figure this out. I must be having a minor stroke so if this is duplicative I apologize. I don’t think it is because all other reference questions I found were for many-to-many relationships… many-to-one.

My scenario is quite simple…

I have an entity (Recording) that has two required properties RecordingLocation and EditingLocation which are both of the same type WorkLocation. Each Recording has exactly one RecordingLocation and one EditingLocation (not many-to-many). I also have the requisite navigation properties.

Each WorkLocation is stand-alone and is not intrinsically linked to the Recording — it’s just a physical place where some work on that Recording took place. So when I delete a recording I do not want to delete the associated WorkLocations.

public class Recording
{
    [Key]
    public virtual int Id { get; set; }

    //... other properties not shown here

    public virtual int RecordingLocationId { get; set; }
    public virtual WorkLocation RecordingLocation { get; set; }

    public virtual int EditingLocationId { get; set; }
    public virtual WorkLocation EditingLocation { get; set; }
{


public class WorkLocation
{
    [Key]
    public virtual int Id { get; set; }
    public virtual WorkLocationType Type { get; set; }
    public virtual string Description { get; set; }
    public virtual LogicalStatus Status { get; set; }
}

// I'll use this on the front-end to filter a selection list
// but don't necessarily assume a Work Location is bound to only items of this type
public enum WorkLocationType
{
    RecordingLocation,
    EditingLocation,
    MasteringLocation
}

What am I missing to get this working?

  • 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-26T23:19:46+00:00Added an answer on May 26, 2026 at 11:19 pm

    Your navigation properties RecordingLocation and EditingLocation are required because the corresponding foreign key properties are not nullable. By convention EF assumes that cascading delete is active for a required one-to-many relationship which causes a problem if you have more than one such relationship refering to the same table – hence the exception.

    You must disable cascading delete (also your business logic seems to require it) which is only possible in Fluent API:

    public class MyContext : DbContext
    {
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Recording>()
                .HasRequired(r => r.RecordingLocation)
                .WithMany()
                .HasForeignKey(f => f.RecordingLocationId)
                .WillCascadeOnDelete(false);
    
            modelBuilder.Entity<Recording>()
                .HasRequired(r => r.EditingLocation)
                .WithMany()
                .HasForeignKey(f => f.EditingLocationId)
                .WillCascadeOnDelete(false);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like a pretty softball question, but I always have a hard time
This seems like a simple question, but I can't find it with the Stack
This seems like a very simple and a very common problem. The simplest example
This seems like a silly question but I would really like your comments and
This seems like such a trivial problem, but I can't seem to pin how
This seems like perhaps a naive question, but I got into a discussion with
This seems like an incredibly dumb question to have to ask, but how do
This seems like it should be obvious but I can't figure it out. Suppose
This seems like a basic question, but I haven't found any clear answers. Essentially,
This seems like it should be something I already know. We need to run

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.