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; }
}
У меня есть этот класс, и я хотел бы запросить базу данных, чтобы получить результаты. вот мой запрос:
foreach (var category in categories)
{
var news = newsRepo.Query("from News n where n.Category ="+category);
}
вот метод Query.
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;
}
и это не работает.
Я получаю следующую ошибку:
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=. ]
Как я могу это исправить?
есть идеи?