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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:35:56+00:00 2026-05-18T05:35:56+00:00

I am trying to map a POCO as a many-to-many relationship. I do not

  • 0

I am trying to map a POCO as a many-to-many relationship. I do not want a property on Behavior that Contains BehavioralEvents. I’m pretty sure the Many-to-Many mapping has to be in both places, however I don’t want the corresponding property on my Behavior class.

I have heard you can use a no-op access operator but im not sure how to do it in Fluent Nhibernate.

Please advise:

public class BehavioralEvent : AggregateRoot    
    {       
        protected internal IList<Behavior> Behaviors { get; private set; }

        public BehavioralEvent()
        {
            Behaviors = new List<Behavior>();
        }
    }

Behavior Class (No reference back to BehavioralEvent)

public class Behavior : AggregateRoot
{
        protected internal virtual string Name { get; private set; }
        protected internal virtual string Definition { get; private set; }           

        public Behavior(string name, Guid id) 
        {
            this.Id = id;
            this.Name = name;               
        }

        protected Behavior(){}          
    }

BehavioralEventClassMap:

public class BehavioralEventClassMap : ClassMap<BehavioralEvent>
    {
        public BehavioralEventClassMap()
        {
            Id(x => x.Id, "BehavioralEventId").GeneratedBy.Assigned();

            HasManyToMany(x => x.Behaviors)
                .Cascade.All()
                .Table("BehaviorData")
                .ParentKeyColumn("BehavioralEventId")
                .ChildKeyColumn("BehaviorId");
        }
    }

BehaviorClassMap:

public class BehaviorClassMap : ClassMap<Behavior>
{
    public BehaviorClassMap()
    {
        Table("Behaviors");
        Id(x => x.Id, "BehaviorId").GeneratedBy.Assigned();
        Map(x => x.Name).Not.Nullable();
        Map(x => x.Definition); 
    }
}
  • 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-18T05:35:56+00:00Added an answer on May 18, 2026 at 5:35 am

    You do not need to map it from both sides.

    I have various mappings like this:

    HasManyToMany(x => x.SomeCollection).Table("MappingTable").ParentKeyColumn("ParentKey").ChildKeyColumn("ChildKey").Cascade.AllDeleteOrphan();
    

    Works like a charm! Map it as Collection or Set (see http://www.codinginstinct.com/2010/03/nhibernate-tip-use-set-for-many-to-many.html).

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

Sidebar

Related Questions

I'm trying to map a many-to-many relationship but my middle table is giving me
Im trying to map urls to numbers in a range [0,50] for porting, that
I'm trying to map a manyToMany relationship in Fluent NHibernate and running into a
I'm trying to map a parent-child relationship using NHibernate (2.1.2), MySql.Data (6.2.2) and MySQL
I have a std::map of Poco::Any which I'm trying to iterate and output to
I am trying to map the following scenario: // SourceA + SourceB to not
I am trying to map a NHibernate formula for a nullable datetime field that
When trying to map an inherited property using AttributeOverride annotation, OpenJPA throws an error
I'm trying to map a one to zero or one relationship in Hibernate. I
I am trying load map region and MKMapView delegate methods are not being called

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.