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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:15:45+00:00 2026-05-24T16:15:45+00:00

My Model looks like like this public class User { public int ID {

  • 0

My Model looks like like this

public class User
{
    public int ID { get; set; }

    public string Name { get; set; }


    /*Users who are following current user*/
    public virtual ICollection<User> Followers { get; set; }

    /*Users whom current user is following*/
    public virtual ICollection<User> Following { get; set; }


    /*current user has ignored these users*/
    public virtual ICollection<User> Ignores { get; set; }

}

To add data

        User john = new User { Name = "john" };
        User mary = new User { Name = "mary" };
        User david = new User { Name = "david" };

        john.Following = new List<User> { mary };
        mary.Followers = new List<User> { john};
        john.Ignores = new List<User> { david};

        context.Users.Add(john);
        context.Users.Add(mary);
        context.Users.Add(david);

        context.SaveChanges();

Doing this is giving error:

Unable to determine a valid ordering for dependent operations. Dependencies may exist due to foreign key constraints, model requirements, or store-generated values.

If i remove the propert Ignores from User Model its working perfect, but with ignores it doesn’t.

I think there is some mapping thats need to be done, please suggest me how can i do this!!

  • 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-24T16:15:47+00:00Added an answer on May 24, 2026 at 4:15 pm

    The problem seems to be that EF does not know which two are a many-to-many and which one is a one-to-many. You could try explicitly stating these rather than relying on convention. Try overriding the OnModelCreating(DbModelBuilder) method of the DbContext class (if you are using DbContext).

    protected override void OnModelCreating(DbModelBuilder mb)
    {
        mb.Entity<User>()
            .HasMany(u => u.Ignores)
            .WithReequired()
            .HasForeignKey(u => u.ID);
    
        mb.Entity<User>()
            .HasMany(u => u.Followers)
            .WithMany(u => u.Following);
            // If you want to specify a table, use the following line:
            // .Map(m => m.ToTable("CustomManyToManyTableName");
    }
    

    Notice: I made this up off the top of my head so don’t rely on my syntax and such precisely, but it should be pretty close.

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

Sidebar

Related Questions

public class User { public int Id {get;set;} public string Name {get;set} public ICollection<User>
This is how my data model for USER looks like public class User {
I have a model that looks like this: public class UserAdminEditViewModel { public User
I have the following code: modelBuilder.Entity<User>().HasMany(x => x.Items).WithRequired(); The model looks like public class
I have a model that looks something like this public class User { public
I have a model that looks like this: public interface IEntity { int Id
My simplified domain model looks something like this: public abstract class Entity<IdK> { public
This is what my data model classes look like: public class Employee { public
My model looks like this: class Staff(models.Model): StaffNumber = models.CharField(max_length=20,primary_key=True) NameFirst = models.CharField(max_length=30,blank=True,null=True) NameLast
I have a rails model that looks something like this: class Recipe < ActiveRecord::Base

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.