Diego, you are da man!, that did it.
In case anyone else is looking at this here is what I did
var criteria =
Session.CreateCriteria(typeof(MyTable)).SetMaxResults(10).Add(
Restrictions.Gt(
Projections.SqlFunction(new
StandardSQLFunction("charindex", NHibernateUtil.Int32),
NHibernateUtil.Int32,
Projections.Constant(theChar),
Projections.Property("Name")), 0)
);
On Jul 12, 9:28 pm, Diego Mijelshon <[email protected]> wrote:
> You can still use the same structure, but you need to replace *"locate"*with:
>
> new StandardSQLFunction("charindex", NHibernateUtil.Int32)
>
> Everything else is unchanged.
>
> The main place for NH documentation, howtos, etc ishttp://nhforge.org/, but
> you can always ask your questions (silly or not) here.
> Several of us also answer questions inhttp://stackoverflow.com/.
>
> Diego
>
>
>
> On Mon, Jul 12, 2010 at 21:57, thecodefool <[email protected]> wrote:
> > Thanks so Much Diego! You Rock
>
> > Unfortunately, that did not work for me as I am using this code
>
> >https://nhibernate.svn.sourceforge.net/svnroot/nhibernate/branches/2....
> > not the one that is in the trunk :( (figured that out when it barked
> > at me for no function locate exists) I will change it to the trunk
> > tomorrow and let you know how it goes.
>
> > 2 Questions:
>
> > trunk is current dev right?
> > Do you have a site or a book that you can direct me to so that I do
> > not have to ask silly questions like this one again?
>
> > Thanks again for your help!
>
> > On Jul 12, 8:33 pm, Diego Mijelshon <[email protected]> wrote:
> > > 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/nhibe.
> > ..
>
> > > > 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]
> > > > >
> > <nhusers%[email protected]<nhusers%252bunsubscr...@googlegroup
> > s.com>>
> > > > .
> > > > 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]<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.