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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:22:20+00:00 2026-05-17T20:22:20+00:00

I have two connected classes defined like this: [ActiveRecord] public class Store : ActiveRecordBase<Store>

  • 0

I have two connected classes defined like this:

    [ActiveRecord]
    public class Store : ActiveRecordBase<Store> {
        [PrimaryKey]
        public int ID { get; set; }

        [HasAndBelongsToMany(Table = "StoreCustJoin",
                             ColumnKey = "storeID",
                             ColumnRef = "customerID")]
        public IList<Customer> customers { get; set; }
    }

    [ActiveRecord]
    public class Customer : ActiveRecordBase<Customer> {
        [PrimaryKey]
        public int ID { get; set; }

        [HasAndBelongsToMany(Table = "Join",
                             ColumnKey = "customerID",
                             ColumnRef = "storeID",
                             inverse = true)]
        public IList<Store> stores { get; set; }
    }

    [ActiveRecord]
    public class Join : ActiveRecordBase<Join> {
        [PrimaryKey]
        public int ID { get; set; }

        [BelongsTo("storeID")]
        public Store store { get; set; }

        [BelongsTo("customerID")]
        public Customer customer { get; set; }

        [Property]
        public int Status { get; set; }
    }

When I connect a Store to a Customer I need to set the status as well. So I tried to do this:

    public void SetLink(Store theStore, Customer theCustomer, int status) {
        var link = new Join()
                       {
                           Status = status,
                           store = theStore,
                           customer = theCustomer
                       };
        theStore.customers.Add(theCustomer);
        theCustomer.stores.Add(theStore);
    }

This creates two entries in ABJoin, the first with the status set, the second without. If I don’t add the objects to their respective lists, it works. But then the link is not reflected in these objects until the current session is closed and the instance is re-downloaded from the DB.

So, is there a way I can set the Status when I create the link and also keep the current objects valid and up to date?

  • 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-17T20:22:21+00:00Added an answer on May 17, 2026 at 8:22 pm

    When your relationship table (in your case the “Join” table) has additional fields other than the FKs to the tables it relates, use [HasMany] instead of [HasAndBelongsToMany], i.e.:

    [ActiveRecord]
    public class Store : ActiveRecordBase<Store> {
        [PrimaryKey]
        public int ID { get; set; }
    
        [HasMany]
        public IList<Join> customers { get; set; }
    }
    
    [ActiveRecord]
    public class Customer : ActiveRecordBase<Customer> {
        [PrimaryKey]
        public int ID { get; set; }
    
        [HasMany]
        public IList<Join> stores { get; set; }
    }
    

    Similar questions:

    • Using Additional Data on Intermediate Table with NHibernate
    • NHibernate: Many-to-many relationship with field in the relationship table
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes which both extend from SQL class like this: class SQL
I have two classes X and Y, like this: class X implements Serializable {
I have two ActiveRecord classes class Product : ActiveRecordBase<Product> { private IList<Usage> _usages =
I have two classes in short here they are: public final class ServerMain {
Say I have two classes: Supplier, and Account. These classes are connected via has_one
I have converted an array to object data like this: <?php $myobject->data = (object)Array('zero','one','two');
Using two barcode readers connected to one machine, I have a need to store
I have two classes, WebServiceRequest and OrderRequest. Each class has properties. OrderRequest inherits from
I have two classes, Database and User. In the Database class I have function
Consider these two classes: public class A { B b; public A(B b) {

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.