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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:35:10+00:00 2026-06-01T11:35:10+00:00

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

  • 0
public class News
{
    public virtual int Id { set; get; }
    public virtual string Title { get; set; }
    public virtual string Thumbnail { set; get; }
    public virtual string Image { set; get; }
    public virtual string NewsContent { set; get; }
    public virtual DateTime DateCreated { set; get; }
    public virtual bool Published { set; get; }
    public virtual int UserCreated { set; get; }
    public virtual Category Category { set; get; }
    public virtual DateTime DateUpdated { set; get; }
    public virtual int ViewCount { set; get; }
}

I have this class and I d like to query the database to get results. here is my query :

        foreach (var category in categories)
        {
            var news = newsRepo.Query("from News n where n.Category ="+category);
        }

here is the Query method.

    public IQueryable<T> Query(string query)
    {
        IQueryable<T> queryable;
        using (var session = SessionFactory.OpenSession())
        using (var transaction = session.BeginTransaction())
        {
            var hql = session.CreateQuery(query);
            var list = hql.List<T>();
            queryable = list.AsQueryable();
            transaction.Commit();
        }
        return queryable;
    }

and it doesnt work.

I get the following error:

could not execute query
[ select news0_.Id as Id13_, news0_.Title as Title13_, news0_.DateCreated as DateCrea3_13_, news0_.DateUpdated as DateUpda4_13_, news0_.NewsContent as NewsCont5_13_, news0_.Published as Published13_, news0_.UserCreated as UserCrea7_13_, news0_.Image as Image13_, news0_.Thumbnail as Thumbnail13_, news0_.ViewCount as ViewCount13_, news0_.Category_id as Category11_13_ from [News] news0_ where news0_.Category_id=. ]

How can i fix it?

any ideas?

  • 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-06-01T11:35:11+00:00Added an answer on June 1, 2026 at 11:35 am

    If you put a break point at the following line of code then you should see that the category variable isn’t getting initialized to what you expect (which should be an integer):

    var news = newsRepo.Query("from News n where n.Category ="+category);
    

    That aside, there are several better ways of facilitating this query. One is to just use Session.Get(id) like so:

    var news = Session.Get<News>(1);
    

    You could also use the NHibernate LINQ provider like so:

    var news = Session.Query<News>().SingleOrDefault();
    

    Only use literal SQL or HQL when absolutely necessary.

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

Sidebar

Related Questions

I have two classes public class News { public virtual int Id { get;
Here is my model: public class NewsCategoriesModel { public int NewsCategoriesID { get; set;
public class Options { public FolderOption FolderOption { set; get; } public Options() {
Model: class News { public $title; public $article; public $date; public $published; public $publisher;
public class TestBL { public static void AddFolder(string folderName) { using (var ts =
public class ToolPartGetLists : Microsoft.SharePoint.WebPartPages.WebPart, ICommunicationInterface { private bool _error = false; //......... protected
public class Order { static Customer cust = new Customer(); string sEmpty = ;
public class Ex7 { private int fld; private void meth(int val) { fld =
public class Test extends Thread{ public void hello(String s){ System.out.println(s); } public void run(){
Suppose I have a class that downloads a news feed from the web public

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.