You were almost there... you are missing the searched for char:
Restrictions.Gt(
Projections.SqlFunction("locate",
NHibernateUtil.Int32,
Projections.Constant(theChar),
Projections.Property("Name")),
0)
Diego
On Mon, Jul 12, 2010 at 20:34, thecodefool <[email protected]> wrote:
> I am trying to use the CHARINDEX function in SQL Server 2008 in a
> query, the query in SQL Server would look like this
> (I know don't use *, just for brevity )
>
> DECLARE @p0 varchar(50);
> SET @p0='Joe';
> SELECT * FROM MyTable WHERE @p0='' OR CHARINDEX(@p0,Name)>0
>
> That of course would show me everything if @p0='' or it would show me
> all the rows that contained 'Joe' in the field "Name"
>
> I have figured out (I think) that CHARINDEX is locate from the src
> (search for "charindex")
>
> https://nhibernate.svn.sourceforge.net/svnroot/nhibernate/trunk/nhibernate/src/NHibernate/Dialect/MsSql2000Dialect.cs
>
> So I assume I should do this:
>
> var criteria =
> Session.CreateCriteria(typeof(MyTable)).SetMaxResults(10).Add(
> // Charindex is locate
> Restrictions.Gt(
> Projections.SqlFunction("locate",
> NHibernateUtil.Int32, Projections.Property("Name")),0));
>
>
> I have been Googling for quite a while now, Can anyone solve or point
> me in the right direction?
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.