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

Ask A Question

Stats

  • Questions 533k
  • Answers 533k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The Python source tree contains an implementation of this: unparse.py… May 17, 2026 at 12:28 am
  • Editorial Team
    Editorial Team added an answer This may get you started down the path that you… May 17, 2026 at 12:28 am
  • Editorial Team
    Editorial Team added an answer Include the properties to be added to your anonymous type.… May 17, 2026 at 12:28 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have two objects, one is in our enterprise level and another in in
I have two objects of the same type, and I want to loop through
I have two objects that are derived from same the base class. Lets say
I have two objects that contain some properties that are exactly the same (same
I have two objects - one that contains some code with will fire an
I have two objects: User and Client, both implements interface IMember interface IMember {
I have two entity objects one that holds billing address information(TBLADDRESS) and one that
I have two objects, let's call them Input and Output Input has properties Input_ID
I have two objects and I want to merge them: public class Foo {
I have two objects: public class ParentObject { // some basic bean info }

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.