Yep, I did that. If I pause the debugger before the test finishes and examine the generated sql in NHProf, it returns the expected row from the db.
On Apr 13, 6:22 pm, Fabio Maulo <[email protected]> wrote: > Populated or not can be a matter of data, what you need to check is the > generated SQL. > If the generated SQL is ok you can run it directly in the DB and then have a > look to data. > > 2010/4/13 Jim Geurts <[email protected]> > > > > > > > Thanks Fabio, > > > Unfortunately, I'm still seeing unexpected behavior when using the > > contains function with hql. It does not populate the enumerable as it > > should. When I remove the contains(...) statement from hql, then > > everything works as expected. > > > My code looks somewhat like the following. My actual code is part of > > an integration test, but this should give you a feel for the flow: > > > string query = "Test"; > > Property = new Property { > > Name = "Test Search", > > Portfolio = portfolio, > > IsDeleted = 0 > > }; > > using (var transaction = Session.BeginTransaction()) { > > Session.Save(Property); > > transaction.Commit(); > > } > > > Session.Clear(); > > try > > { > > IEnumerable<Property> properties; > > using (var transaction = propertyService.BeginTransaction()) > > { > > properties = Session.CreateQuery("from Property p where > > p.IsDeleted = false and p.Portfolio = :portfolio and > > contains(p.Name, :query)") > > .SetFirstResult((page - 1) * itemsPerPage) > > .SetMaxResults(itemsPerPage) > > .SetParameter("query", query) > > .SetParameter("portfolio", portfolio) > > .List<Property>(); > > transaction.Commit(); > > } > > // At this point, properties should be populated, but it is not. > > In fact, NHProf doesn't see the query go through until after the > > assert. > > Assert.AreEqual(1, properties.Count(), "Incorrect number of > > results returned for query: " + query); > > Assert.AreEqual(Property.Id, properties.ElementAt(0).Id, "Invalid > > property returned for specified query: " + query); > > } > > finally > > { > > using (var transaction = Session.BeginTransaction()) { > > Session.Delete(Property); > > transaction.Commit(); > > } > > } > > > As I said before, if I remove the contains(p.Name, :query) part from > > hql, then this code runs fine. Any help with what is going on is > > appreciated, > > > Jim > > > On Apr 13, 2:00 pm, Fabio Maulo <[email protected]> wrote: > > > public class MyDialect : MsSql2008Dialect > > > { > > > public MyDialect() > > > { > > > RegisterFunction("freetext", new StandardSQLFunction("freetext", null)); > > > RegisterFunction("contains", new StandardSQLFunction("contains", null));} > > > } > > > > 2010/4/13 Jim Geurts <[email protected]> > > > > > Can anyone help with getting this to work as expected? > > > > > Thanks, > > > > > Jim > > > > > On Apr 12, 6:28 pm, Jim Geurts <[email protected]> wrote: > > > > > I'm not sure I completely follow you. I looked at the NH source and > > > > > only found one example of freetext search. I didn't find anything > > > > > related to the contains function. In a unit test, they register a > > > > > function similar to: RegisterFunction("freetext", new > > > > > SQLFunctionTemplate(null, "freetext($1,$2)")); and then use > > > > > freetext(...) in their hql. I tried that and it didn't change the > > > > > behavior I'm seeing. > > > > > > I went back to my code and simplified the expression as much as > > > > > possible. I found that checking a related object value is what is > > > > > breaking things. > > > > > > This works (even without specifying the custom function in the > > > > > dialect): > > > > > > return Session.CreateQuery("from MyObject p where p.IsDeleted = false > > > > > and CONTAINS(p.Name, :query)") > > > > > .SetFirstResult((page - 1) * itemsPerPage) > > > > > .SetMaxResults(itemsPerPage) > > > > > .SetParameter("query", query) > > > > > .Future<MyObject>(); > > > > > > This does not: > > > > > > return Session.CreateQuery("from MyObject p where p.IsDeleted = false > > > > > and CONTAINS(p.Name, :query) and p.Category = :category") > > > > > .SetFirstResult((page - 1) * itemsPerPage) > > > > > .SetMaxResults(itemsPerPage) > > > > > .SetParameter("query", query) > > > > > .SetParameter("category", category) > > > > > .Future<MyObject>(); > > > > > > Jim > > > > > > On Apr 12, 5:33 pm, Fabio Maulo <[email protected]> wrote: > > > > > > > This post represent my feeling when I saw the problemhttp:// > > > > fabiomaulo.blogspot.com/2009/07/art-to-invent-mssqls-artists.html > > > > > > > 2010/4/12 Fabio Maulo <[email protected]> > > > > > > > > We should have an example in our tests. > > > > > > > Neither CONTAINS nor FREETEXT does return a boolean and we have > > > > implemented > > > > > > > something else to support it. > > > > > > > > 2010/4/12 Jim Geurts <[email protected]> > > > > > > > > Hi all, > > > > > > > >> I have a custom function, that I'm adding to the Sql2008 > > dialect, > > > > that > > > > > > >> allows me to do some fulltext searching across my objects: > > > > > > > >> public class FreeTextDialect:MsSql2008Dialect > > > > > > >> { > > > > > > >> public FreeTextDialect() > > > > > > >> { > > > > > > >> RegisterFunction("contains", new > > > > > > >> SQLFunctionTemplate(NHibernateUtil.Boolean, "CONTAINS(?1,?2)")); > > > > > > >> } > > > > > > >> } > > > > > > > >> When I use that function as part of hql, the results are not > > > > populated > > > > > > >> even though the query brings back objects. NHProf shows that > > the > > > > > > >> correct sql query is being generated and there are results from > > that > > > > > > >> query. Example usage is: > > > > > > > >> return Session.CreateQuery("from MyObject p where p.IsDeleted = > > > > false > > > > > > >> and contains(p.Name, :query)") > > > > > > >> .SetFirstResult((page - 1) * itemsPerPage) > > > > > > >> .SetMaxResults(itemsPerPage) > > > > > > >> .SetParameter("query", query) > > > > > > >> .List<MyObject>(); > > > > > > > >> However, if I do not use the contains function, then things work > > as > > > > > > >> expected: > > > > > > > >> return Session.CreateQuery("from MyObject p where p.IsDeleted = > > > > false > > > > > > >> and p.Name like :query") > > > > > > >> .SetFirstResult((page - 1) * itemsPerPage) > > > > > > >> .SetMaxResults(itemsPerPage) > > > > > > >> .SetParameter("query", "%" + query + "%") > > > > > > >> .List<MyObject>(); > > > > > > > >> Is my syntax incorrect for using the contains function? How can > > I > > > > > > >> help track down why the list is not being populated? This is > > using > > > > NH > > > > > > >> 3.0 Alpha 1. > > > > > > > >> Thanks for your help, > > > > > > > >> Jim > > > > > > > >> -- > > > > > > >> 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>> > > > > <nhusers%[email protected]<nhusers%252bunsubscr...@googlegroup > > > > s.com> > > <nhusers%252bunsubscr...@googlegroup s.com>> > > > > > > >> . > > > > > > >> For more options, visit this group at > > > > > > >>http://groups.google.com/group/nhusers?hl=en. > > > > > > > > -- > > > > > > > Fabio Maulo > > > > > > > -- > > > > > > Fabio Maulo > > > > > -- > > > > 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. > > > > -- > > > Fabio Maulo > > > -- > > 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. > > -- > Fabio Maulo -- 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.
