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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:01:10+00:00 2026-06-01T21:01:10+00:00

I have the following two entities: public class Field { public int FieldID {

  • 0

I have the following two entities:

public class Field {
    public int FieldID { get; set; }
    public String Name { get; set; }
    public int LocationID { get; set; }

    public virtual ICollection<FieldPlanning> FieldPlannings { get; set; }
}

public class Timeslot {
    public int TimeslotID { get; set; }
    public DateTime Start { get; set; }
    public int MatchDayID { get; set; }

    public virtual ICollection<FieldPlanning> FieldPlannings { get; set; }
}

Now a combination of these two entities makes up the following entity:

public class FieldPlanning {
    public int FieldPlanningID { get; set; }
    public int TimeslotID { get; set; }
    public int FieldID { get; set; }


    public virtual Timeslot Timeslot { get; set; }
    public virtual Field Field { get; set; }
    public virtual Match Match { get; set; }
}

This entity would then also have a navigation property to the Match entity, but I’ve left this out for brevity.

When either a Field or a Timeslot is deleted I want it to delete the associated FieldPlanning records as well.

If I run the application I get the error that ‘Timeslot_FieldPlanning may cause cycles or multiple cascade paths’. If I then edit the modelcreating like this:

        modelBuilder.Entity<Timeslot>()
            .HasMany(ts => ts.FieldPlannings)
            .WithRequired(fp => fp.Timeslot)
            .HasForeignKey(fp => fp.TimeslotID)
            .WillCascadeOnDelete(false);

If I then delete a Field, the FieldPlanning is deleted with it without problem. If I try to delete a Timeslot, I get the same error as before.

How can I fix it so that I can delete either of Field or Timeslot and for both Entities the CascadeOnDelete can be true?

I read Hans Riesebos’ answer here but I couldn’t figure out how to apply it to my problem.

EDIT:
My Location Entity:

public class Location {
    public int LocationID { get; set; }
    public String Name { get; set; }
    public Address Address { get; set; }
    public int TournamentID { get; set; }

    public virtual Tournament Tournament { get; set; }

    public virtual ICollection<Field> Fields { get; set; }
}

My Match Entity:

public class Match {
    public int MatchID { get; set; }
    public Boolean Forfeited { get; set; }
    public int TeamAID { get; set; }
    public int TeamBID { get; set; }
    public int FieldPlanningID { get; set; }
   

    public virtual Team TeamA { get; set; }
    public virtual Team TeamB { get; set; }
    public virtual FieldPlanning FieldPlanning { get; set; }

    public virtual ICollection<Official> Officials { get; set; }
}

When trying it out, I specifically commented the navigation property to Match, so I could make sure it first worked without Match because I know I have problem in the relationship between FieldPlanning and Match, as this is a 0..1 to 0..1 relationship. But I don’t see how this matters in my current problem (so long as I keep the navigation property of Match in FieldPlanning commented).

  • 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-01T21:01:12+00:00Added an answer on June 1, 2026 at 9:01 pm

    After searching a little bit more I found this thread which correctly states that SQL Server doesn’t allow this. I thought the problem was with the Entity Framework but after trying to recreate he tables in SSMS I noticed it still didn’t work.

    The solution is to disable one of the cascading effects and use a trigger (or code) to first delete the child rows.

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

Sidebar

Related Questions

I have two entities, defined as following public class Corporation { public int Id{get;set;}
I have following two entities public class User { public int UserId { get;
I have the following two entities: Person.java: @Entity @Table(name=PERSON) public class Person { @Id
I have following two entities public class User { [Key] public int Id {
I have the following two entities: public class Entity1 { public IList e2 {
We have the following two entities with many-to-many association: @Entity public class Role {
I have two entities like the following: @Entity public class Trip { @OneToMany(mappedBy =
I have two entities: ResourceFile: @Entity @Table(name = resource_file) public class ResourceFile extends IdEntity<Integer>
Consider the following Entities. public class Product{ int id; Date effectiveDate; Date expiryDate; Set<Inventory>
I have two entities: @Entity public class File ....... @Id @GeneratedValue(strategy=GenerationType.AUTO) private int 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.