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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:57:42+00:00 2026-05-28T03:57:42+00:00

I’m just starting out with EF CF (coming from PHP/MySQL land) and I’m hoping

  • 0

I’m just starting out with EF CF (coming from PHP/MySQL land) and I’m hoping someone can help me understand what I’m doing wrong here.

Using the many great tutorials out there, I’ve created my model classes with relationships and the DB was being created and updated ok. But now I’m getting an issue with Cascade Delete.

From what I understand, this is caused when an entity can be deleted through Cascade Delete in more than way thus creating orphan records – is that right?

public class jbsEntity
{
    [Timestamp]
    public Byte[] TimeStamp { get; set; }

    //public User CreatedBy { get; set; }
    //public User UpdatedBy { get; set; }
}

public class Customer : jbsEntity
{
    public int Id { get; set; }
    public string Salutation { get; set; }

    [Required, StringLength(128)]
    public string FirstName { get; set; }

    [Required, StringLength(128)]
    public string LastName { get; set; }

    public string BillingName { get; set; }

    [Required, StringLength(128)]
    public string Address { get; set; }

    [Required, StringLength(128)]
    public string Suburb { get; set; }

    [Required, StringLength(4)]
    public string Postcode { get; set; }

    public string BillingAddress { get; set; }
    public string BillingSuburb { get; set; }
    public string BillingPostcode { get; set; }

    public virtual List<Contact> Contacts { get; set; }

    public virtual List<Residence> Residences { get; set; }

}

public class Residence : jbsEntity
{
    public int Id { get; set; }

    [Required, StringLength(128)]
    public string Name { get; set; }

    [Required, StringLength(128)]
    public string Address { get; set; }

    [Required, StringLength(128)]
    public string Suburb { get; set; }

    [Required, StringLength(4)]
    public string Postcode { get; set; }

    public bool Active { get; set; }
    public string AccessInstructions { get; set; }
    public string ServiceFrequency { get; set; }
    public string RegularServiceCost { get; set; }

    [Required]
    public int CustomerId { get; set; }
    public virtual Customer Customer { get; set; }

    public virtual List<Contact> Contacts { get; set; }

    public virtual List<Pool> Pools { get; set; }

    public virtual List<Job> Jobs { get; set; }

    public virtual List<Image> Images { get; set; }

}

public class Pool : jbsEntity
{
    public int Id { get; set; }

    [Required, StringLength(128)]
    public string Name { get; set; }

    [Required, StringLength(128)]
    public string Size { get; set; }
    public string AccessInstructions { get; set; }
    public string SurfcaceType { get; set; }
    public bool Indoor { get; set; }
    public decimal TargetPH { get; set; }
    public decimal TargetIron { get; set; }
    public decimal TargetCopper { get; set; }
    public decimal TargetCalcium { get; set; }
    public decimal TargetChlorine { get; set; }
    public decimal TargetAlkaline { get; set; }
    public decimal TargetStabiliser { get; set; }

    [Required]
    public int ResidenceId { get; set; }
    public virtual Residence Residence { get; set; }

    public virtual List<JobService> JobServices { get; set; }

    public virtual List<Image> Images { get; set; }

}

public class Equipment : jbsEntity
{
    public int Id { get; set; }

    [Required, StringLength(128)]
    public string Name { get; set; }
    public string Description { get; set; }
    public DateTime Installed { get; set; }
    public DateTime WarrantyExpiration { get; set; }
    public string Status { get; set; }

    [Required]
    public int PoolId { get; set; }
    public virtual Pool Pool { get; set; }

    public virtual List<Image> Images { get; set; }

}

public class Contact : jbsEntity
{
    public int Id { get; set; }
    public string Salutation { get; set; }

    [Required, StringLength(128)]
    public string FirstName { get; set; }

    [Required, StringLength(128)]
    public string LastName { get; set; }
    public string Email { get; set; }
    public string Mobile { get; set; }
    public string Phone { get; set; }

}

public class Image : jbsEntity
{
    public int Id { get; set; }
    public string FileName { get; set; }
    public string FilePath { get; set; }
    public string MimeType { get; set; }
}

public class Job : jbsEntity
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public string InvoiceNumber { get; set; }
    public string Comments { get; set; }
    public string CompletionNotes { get; set; }
    public string DpscActionRequired { get; set; }
    public string WorkPerformed { get; set; }
    public string NextCallInstruction { get; set; }
    public bool ServiceComplete { get; set; }
    public DateTime DueDate { get; set; }
    public DateTime ScheduledDate { get; set; }
    public DateTime CompletionDate { get; set; }

    [Required]
    public int ResidenceId { get; set; }
    public virtual Residence Residence { get; set; }

    public virtual List<JobService> JobServices { get; set; }

    public virtual List<Image> Images { get; set; }

}

public class JobService : jbsEntity
{
    public int Id { get; set; }
    public string Name { get; set; }
    public bool SkimSurface { get; set; }
    public bool BrushWalls { get; set; }
    public bool Vacuum { get; set; }
    public bool BackwashRinse { get; set; }
    public bool EmptyBaskets { get; set; }
    public bool CleanElectrodes { get; set; }
    public bool BalanceWater { get; set; }
    public bool AddedAcid { get; set; }
    public bool AddedClarifier { get; set; }
    public bool SwimClearOnsite { get; set; }
    public decimal PH { get; set; }
    public decimal Iron { get; set; }
    public decimal Copper { get; set; }
    public decimal Calcium { get; set; }
    public decimal Chlorine { get; set; }
    public decimal Alkaline { get; set; }
    public decimal Stabiliser { get; set; }

    [Required]
    public int JobId { get; set; }
    public virtual Job Job { get; set; }

    [Required]
    public int PoolId { get; set; }
    public virtual Pool Pool { get; set; }

    public virtual List<Image> Images { get; set; }

}


public class User : jbsEntity
{
    public int Id { get; set; }
    [Required]
    public string UserName { get; set; }
    [Required]
    public string FirstName { get; set; }
    [Required]
    public string LastName { get; set; }
    [Required]
    public string Password { get; set; }
    [Required, Compare("Password")]
    public string ComparePassword { get; set; }
}

and I get this error:

{"Introducing FOREIGN KEY constraint 'Pool_Residence' on table 'Pools' 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 think the relationships causing the issue are:

Customer -> Residences -> Pools
Job -> JobServices
Residence -> Jobs
Pools -> JobServices

Can anyone help me understand what I’m doing wrong and how I can work around it? Any other suggestions welcome as well!

Thanks in advance.

  • 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-28T03:57:43+00:00Added an answer on May 28, 2026 at 3:57 am

    Actually you are not doing anything wrong but SQL Server doesn’t like to handle the multiple cascade delete paths. There are actually two delete paths from Residence to Pool.

    1. The Direct relationship, and
    2. Through Residence -> Job -> JobService -> Pool

    In your model all of the foreign key columns are non-nullable. Hence EF tries to create FKs with cascade deletes.

    To avoid the problem make one of the FKs nullable and handle the deletion of child entities through an alternate mechanism such as a Stored Procedure, Trigger, Through code.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is

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.