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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:01:56+00:00 2026-05-23T19:01:56+00:00

i’m trying to upgrade an old CMS to use NHibernate and can’t deter from

  • 0

i’m trying to upgrade an old CMS to use NHibernate and can’t deter from the original database structure much. Here is the bit which is causing an issue. Say i have the following 2 tables:

Articles: 
- Id (PK, Identity)
- Title 
- Content 

Meta: 
- ArticleId (PK, FK to Articles)
- Description 
- Keywords 

I have created the following classes:

public class Article { 
  public virtual int Id { get; set; } 
  public virtual string Title { get; set; } 
  public virtual string Content { get; set; } 
} 

public class Meta : IComponent { 
  public virtual string Description { get; set; } 
  public virtual string Keywords { get; set; } 
}

public interface IComponent {
}

Usually the Meta would normally be mapped as a component (or a one to one relationship) property on the Article class. However in the application i’m building an admin can enable/disable the components that apply to articles. Also i’d like them to extend the application to add their own components without touching the Article class.

For them reasons i can’t add a property against the Article class. Now ideally in my code i’d like to be able to say:

var articles = session.Query<Article>()
    .Fetch(a = a.Component<Meta>())
    .Where(a => a.Component<Meta>().Keywords.Contains("Some Word"))
    .ToList();

// This wouldn't generate an extra SQL statement
var keywords = articles[0].Component<Meta>().Keywords;

Which would generate the following SQL (or similar):

SELECT * FROM Articles INNER JOIN Meta ON Articles.Id = Meta.ArticleId WHERE Meta.Keywords LIKE ‘%Some Word%’

Is it possible to map the Component method so that it does an inner join to get the Meta. The concept seems pretty simple but i don’t have a clue where begin. I’d really appreciate the help.

Thanks

  • 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-23T19:01:56+00:00Added an answer on May 23, 2026 at 7:01 pm

    Given this:

    public class Article
    {
        public virtual int ArticleId { get; set; }
        public virtual string Title { get; set; }
        public virtual string Content { get; set; }
    }
    
    
    public class Meta : IComponent
    {
        public virtual Article Article { get; set; }
    
        public virtual int MetaId { get; set; }
        public virtual string Description { get; set; }
        public virtual string Keywords { get; set; }
    }
    

    AFAIK, you cannot Fetch something that isn’t part of an entity. So from your example, it’s not possible to fetch Meta from the Article entity.

    So if you want to fetch the other info of an Article, you just have to join Article to them, then project the complete data in your Linq, example:

    var articles =
            from a in s.Query<Article>()
            join m in s.Query<Meta>() on a equals m.Article
            where m.Keywords.Contains("Some Word")
            select new { a, m };
    
    foreach(var x in articles)
        Console.WriteLine("{0} {1}", x.a.Title, x.m.Description);
    

    Resulting query:

    select *
    from [Article] article0_, [Meta] meta1_ 
    where meta1_.ArticleId = article0_.ArticleId 
        and meta1_.Keywords like '%Some Word%'
    

    Another approach, start from Meta, then fetch the Article; on query, this will join the Article immediately, i.e. no lazy loading:

    var artB =
            from m in s.Query<Meta>().Fetch(x => x.Article)
            where m.Keywords.Contains("Some Word")
            select m;
    
    foreach (var x in artB)
        Console.WriteLine("{0} {1}", x.Article.Title, x.Description);
    

    Resulting query:

    select *
    from [Meta] meta0_ 
    left outer join [Article] article1_ on meta0_.ArticleId = article1_.ArticleId 
    where meta0_.Keywords like '%Some Word%'
    

    To keep an Article having only one Meta, put a Unique on Meta’s reference:

    create table Article
    (
    ArticleId int identity(1,1) not null primary key,
    Title varchar(100) not null,
    Content varchar(100) not null
    );
    
    create table Meta
    (
        -- this prevents an Article having two Meta
    ArticleId int not null references Article(ArticleId) unique, 
    
    MetaId int identity(1,1) not null primary key,
    
    Description varchar(100) not null,
    Keywords varchar(100) not null
    );
    
    insert into Article(Title,Content) values('Great','Yeah')
    
    insert into Meta(ArticleId, Description, Keywords) values(1,'Oh','Some Word');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a view passing on information from a database: def serve_article(request, id): served_article
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.