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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:42:59+00:00 2026-05-27T22:42:59+00:00

There’s an entity A . In addition, there’s an entity B which has two

  • 0

There’s an entity A.

In addition, there’s an entity B which has two associations with A.

A has a collection of B.

This collection must load any B if one of associated A is the parent of loaded A.

Problem is collection mapping on A must filter children based on checking if one of two A associations is the parent one.

How can I achieve that?

Note: Order doesn’t matter, so you can suggest some mapping using bag.

Note 2: Please suggest how to achieve that using an XML mapping, I won’t do it in code.

UPDATE: Real-world scenario:

it’s all about a friendship implementation. I want to map a collection of Friendship in an entity UserProfile. Friendship has two associations representing the relation: OneUser, OtherUser. If I want to get all friends for me, I need to check both properties, because one is my friend if one of both properties are myself.

  • 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-27T22:43:00+00:00Added an answer on May 27, 2026 at 10:43 pm

    IF you are willing to move the solution slightly out of the data domain, your users could have a one-to-many relationship of other users they have assigned as friends. This could be protected or private if you don’t want it to leak out.

    Then, you implement a public property that defines an actual Friendship as requiring the relationship in both directions. Maybe something like:

    public List<User> Friends {
        this.assignedFriends.Where(f => f.assignFriends.Contains(this)).ToList();
    }
    

    You’ll want to make sure you are using a form of 2nd level cache if you do this however, otherwise requests to this property will hammer your database.


    If instead you need to return a collection of a dedicated Friendship object, it depends on how you are persisting those entries and how you have mapped that class.

    One option would be to define Friendship to simply have three columns, a primary key, and two foreign keys back to the User table. You then require a little bit of logic whenever someone tries to add a friend: you first need to check if half of the relationship already exists..

    var f = session.Query<Friend>()
        .Where(x => x.User1 == YourCurrentUser)
        .Cacheable()
        .FirstOrDefault();
    

    then if it exists you assign the other half of the relationship

    f.User2 = TheOtherUser;
    

    otherwise create a new object:

    f = new Friendship();
    f.User1 = YourCurrentUser;
    

    and after either branch:

    session.SaveOrUpdate(f);
    

    then a Users friends becomes

    public property List<Friendship> {
        session.Query<Friendship>()
            .Where(f => 
                f.User1 != null && f.User2 != null
                && (f.User1 == this || f.User2 == this)
            ).Cacheable()
            .ToList();
    }
    

    Please note, I’m not near my installation of VS. Please excuse typos or if I’ve made obvious blundering errors (it’s 2:30am where I am presenltly)

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

Sidebar

Related Questions

There are several shading languages available today like GLSL, HLSL, CG, which one to
There must be a simple solution to this, but after 4 hours of browsing
There are two layers (Image control with PNG bitmap) inside Grid (or Canvas): one
There are two weird operators in C#: the true operator the false operator If
There are two popular closure styles in javascript. The first I call anonymous constructor
There is previous little on the google on this subject other than people asking
There are numerous Agile software development methods. Which ones have you used in practice
There are several types of objects in a system, and each has it's own
There is one table T ( id integer, primary key ( id). I want
There is a file as data.html. How to display the contents of this file

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.