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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:53:25+00:00 2026-05-25T06:53:25+00:00

I’m having an issue with persisting a field which is in my were clause

  • 0

I’m having an issue with persisting a field which is in my were clause on a ManyToMany releationship, but doesn’t explicityly exist on the class mapping. Hard to explain but its the “is_expred” field in the below classes and mappings.

I have the following two classes:

public class Publication
{
    public virtual int Id {get; set;}

    public virtual string Name {get; set;}
}

public class Role
{
    public virtual int Id {get; set;}
    public virtual string Name {get; set;}

    public virtual IEnumerable<Publication> CurrentPublications {get; set;}

    public virtual IEnumerable<Publication> ExpiredPublications {get; set;}
}

Where a publication can exist in either or both the CurrentPublications and ExpiredPublications. (and no, I can’t put the expired field on the Publication, as its only expired for this particular role – it might be current on a different role)

The DB for this is:

role
{
    role_id     int (PK)
    role_name   varchar(50)
}

role_pub
{
    role_id     int (PK)
    pub_id      int (PK)
    is_expired  bit
}

pub
{
    pub_id      int (PK)
    pub_name    varchar(50)
}

And the fluent mapping:

public class RoleMapping : ClassMap<Role>
{
    public RoleMapping()
    {
        Table("role");
        Id(x => x.Id, "role_id").GeneratedBy.Identity();
        Map(x => x.Name, "role_name").Not.Nullable();

        HasManyToMany<Publication>(x => x.CurrentPublications)
            .Table("role_pub")
            .ParentKeyColumn("role_id")
            .ChildKeyColumn("pub_id")
            .Where("is_expired = 0")
            .LazyLoad();

        HasManyToMany<Publication>(x => x.ExpiredPublications)
            .Table("role_pub")
            .ParentKeyColumn("role_id")
            .ChildKeyColumn("pub_id")
            .Where("is_expired = 1")
            .LazyLoad();
    }
}


public class PublicationMapping : ClassMap<Publication>
{
    public PublicationMapping()
    {
        Table("pub");
        Id(x => x.Id, "pub_id").GeneratedBy.Identity();
        Map(x => x.Name, "pub_name").Not.Nullable();
    }
}

When I do the select on a role, the Current and Expired Publications are populated with the correct Publications, but when I add new publciations to either Current or Expired lists, it always saves the is_expired field as 0, which is the default value of “is_expired” in the DB.

Does anyone have any idea on wha tthe correct way of mapping this releationship and populating the “is_expired” field correctly?

Thanks for your help

Saan

  • 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-25T06:53:26+00:00Added an answer on May 25, 2026 at 6:53 am

    the where only filters on SELECT but never fills up the columns on INSERT. you could introduce a class RolePublication which has the is_expired mapped

    public class RolePublication
    {
        public virtual Role Role {get; set;}
        public virtual Publication Publication {get; set;}
        public virtual bool IsExpired {get; set;}
    }
    
    public class Role
    {
        ...
        internal protected virtual ICollection<RolePublication> Publications {get; set;}
    
        public virtual IEnumerable<Publication> CurrentPublications
        { get { return Publications.Where(rp => rp.IsExpired == false).Select(rp => rp.Publication); ) } }
    
        public virtual IEnumerable<Publication> ExpiredPublications
        { get { return Publications.Where(rp => rp.IsExpired == true).Select(rp => rp.Publication); ) } }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.