Create a search criteria in Nhibernate

I have a table ‘Post’ which has 3 columns :

ID

PostTitle

Tags

I want to write a search function in my repository  which search on “Tags” columns and  returns the posts list.

Here is the code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Criterion;
using VOITH.MyProject.Repository;
using VOITH.MyProject.Domain;
using VOITH.MyProject.Domain.Entities;

      public    IList GetPostByTags(string tags)
        {
            IList postList = GetNHBSession()
                       .CreateCriteria(typeof(Post))
                       .Add(Restrictions.Like("Tags",tags,MatchMode.Anywhere))
                       .List();

            return postList;

        }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s