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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:35:57+00:00 2026-06-04T04:35:57+00:00

I have the following (simplified) classes: public class Person { public string Id {get;

  • 0

I have the following (simplified) classes:

public class Person
{
   public string Id {get; set;}  //Ignore the fact that the Id is string -- legacy system
   public string Firstname {get; set;}
   public ICollection<Member> Memberships {get; set;}
   ...
}

public class Account
{
   public string Id {get; set;}
   public string AccountType {get; set;}
   ...
}

public class Member
{
   public string AccountNumber {get; set;}
   public string PersonNumber {get; set;}
   public Account Account {get; set;}
   public Person Person {get; set;}
   ...
 }

and the following EF configuration:

//In Accounts configuration class
ToTable("missacct");
HasKey(a => a.Id);

//In Members Configuration class
ToTable("members");
HasKey(a => new { a.AccountNumber, a.PersonNumber});
HasRequired(a => a.Person).WithMany().HasForeignKey(p => p.PersonNumber);
HasRequired(a => a.Account).WithMany().HasForeignKey(a => a.AccountNumber);

//In Persons Configuration Class
ToTable("person");
HasKey(p => p.Id);
HasMany(p => p.Memberships).WithOptional().HasForeignKey(p => p.PersonNumber);

The intent here is that there are persons and accounts. An account can not exist without members and a member is always a person. But, a person can exist without being a member of an account.

The idea is I want to be able to query the following:

  1. Given a specific account number I want to find all the people on the account.
  2. Given a first/last name combination I want to find all persons with matching names and any accounts that they may be members of.

What I have does not currently seem to work. I’m getting a circular reference error but I’m not quite sure where I’ve gone wrong.

Thanks for any help you can offer!

  • 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-04T04:35:58+00:00Added an answer on June 4, 2026 at 4:35 am

    You are defining two separate relationships instead of one bidirectional relationship. Try this:

    //In Accounts configuration class
    ToTable("missacct");
    HasKey(a => a.Id);
    
    //In Members Configuration class
    ToTable("members");
    HasKey(a => new { a.AccountNumber, a.PersonNumber});
    HasRequired(m => m.Person).WithMany(p => p.Memberships).HasForeignKey(p => p.PersonNumber);
    HasRequired(m => m.Account).WithMany().HasForeignKey(a => a.AccountNumber);
    
    //In Persons Configuration Class
    ToTable("person");
    HasKey(p => p.Id);
    HasMany(p => p.Memberships).WithOptional(m => m.Person).HasForeignKey(p => p.PersonNumber);
    

    An account can not exist without members …

    You will have to enforce this part in your application logic. At relationship level you can only say that a member must have an account.

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

Sidebar

Related Questions

As a simplified example, I have the following data classes: public class Employee {
I have the following (greatly simplified) classes: public class Customer { [Required(ErrorMessageResourceName=Required, ErrorMessageResourceType=typeof(ResourcesCommon.ValidationStrings))] public
i have the following (simplified) domain classes class Filter { String name static hasMany
Having the following classes (highly simplified): public class Child { public string Label; public
I have the following (simplified) XML that I get in a system environment: <?xml
I have the following object: public class MyClass { public int Id { get;
I have the following classes, they are bit simplified for example. class LineInfo {
I have following situation (simplified, of course): MyDomain.groovy: class MyDomain { MyAnotherDomain anotherDomain //
I have the following (simplified) public enum Level { Bronze, Silver, Gold } public
Lets say we have the following models: (simplified) class Collection(models.Model): slug = models.SlugField() class

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.