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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:54:52+00:00 2026-05-16T15:54:52+00:00

I have two objects… and if I compile a program with either one, it

  • 0

I have two objects… and if I compile a program with either one, it works fine, but when they both exist in the same program, I get the exception…

“Entities in ‘ObjectContext.UnitSet’ participate in the ‘Sheet_Statistics’ relationship. 0 related ‘Sheet’ were found. 1 ‘Sheet’ is expected.”

class Unit
{
 public int Id;
 public string Name;
}
class Template
{
 public int Id;
 public virtual ICollection<Unit> Units
}

class Sheet
{
 public int Id;
 public virtual ICollection<Unit> Units
}

Then their configurations..

TemplateConfiguration : EntityConfiguration
// ….

        //// map the collection entity
        HasMany(k => k.Units).WithRequired()
            .Map("template.units",
                (template, unit) => new
                {
                    Template = template.Id,
                    Unit = unit.Id
                });

SheetConfiguration : EntityConfiguration
// ….

        //// map the collection entity
        HasMany(k => k.Units).WithRequired()
            .Map("sheet.units",
                (sheet, unit) => new
                {
                    Sheet = sheet.Id,
                    Unit = unit.Id
                });

UnitConfiguration : EntityConfiguration<Unit>
// 
            // Initialize the Primary Key
            HasKey(k => k.Id);
            // Initialize that the Key Increments as an Identity
            Property(k => k.Id).IsIdentity();


var templates = new List<Template>
                {
                    new Template
                    {
                        Name = // ..,
                        Units = new List<Unit>
                        {
                            new Unit
                            {
                                // ...
                            }
                        }
                    }
                };
                templates.ForEach(x =>
                {
                    context.Templates.Add(x);
                });
                context.SaveChanges(); // <-- Exception Happens Here, I never even get to try to add Sheets.
  • 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-16T15:54:52+00:00Added an answer on May 16, 2026 at 3:54 pm

    I’m taking a stab at this because without seeing all your code, I can’t solve much more of it. I think your problem is that you’re creating Units but not setting some sort of Sheet property (you need to provide all your entity/config code). You need to create the Sheet and Unit both before you can save the Unit or Sheet since they have a required reference (hence the error you’re getting). If you provide more code I’ll be able to refine my answer better.

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

Sidebar

Related Questions

If I have two objects on the heap referring to each other but they
I have two objects both of the same type, for instance: typedef struct s_Object
I have two objects that represent the same event instance --- one holds the
I have two objects that are searching for one-another on the stage. They move
I have two objects of the same class (Model) type. I want to check
Suppose that I have two objects with the same property name that I am
Let's say we have two objects. Furthermore, let's assume that they really have no
I have two objects (instances of the same class) with a bunch of properties,
I have two objects ( Foo and Bar ) that have a one-to-zero-or-one relationship
I have two objects that have a ManyToMany relationship with one another through a

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.