开发者

Get all Caterory values from a column

NHibernate. I need get all the values from a column categories from a sql data base.

I need put in a List, and return it.

I have this:

    public IList<Movie> GetMovieCategories() 
    {
        using (ISession session = NHibernateSessionBuilder.OpenSession()) 
        {
            return session.C开发者_开发问答reateCriteria(typeof(Movie)).List<Movie>();
        }
    }

the problem whith this is that return all the table "Movie", and I need only the column "Category".

How can I do this??


Try this:

public IList<string> GetMovieCategories() 
{
    using (ISession session = NHibernateSessionBuilder.OpenSession()) 
    {
        return session.CreateCriteria(typeof(Movie)).SetProjection(Projections.Property("Category")).List<string>();
    }
}


Should be able to do something like this (assuming category is a string):

public IList<string> GetMovieCategories() 
{
    using (ISession session = NHibernateSessionBuilder.OpenSession()) 
    {
        return session.QueryOver<Movie>()
               .Select(c => c.Category)
               .List<string>();
    }
}

This is also assuming you are using nhibernate 3.x.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜