Although you should use a DetachedCriteria with Subqueries.PropertyIn to get
the result you really want (search for examples in this group), the error
you're getting is because CreateAlias doesn't change the "context" of the
criteria.
The message makes it clear: you are trying to access a "note" property in
Company.
If you use CreateAlias, you can refer to that property as "note.note" (the
naming you're using doesn't help much. That property should be called Text).
If you use CreateCriteria instead, it'll work as it's written.

   Diego


On Sat, Feb 20, 2010 at 16:36, Dmitry Starosta <[email protected]>wrote:

> I have a class that looks like this:
>
> public class Company
> {
>   // ....
>
>   ICollection<string> Notes;
>
>  // ....
> }
>
> The table for notes has 2 fields:
>
> table notes
>   id int,  -- company Id
>   note nvarchar(50)
>
> The mapping in fluent nhibernate looks like this:
>
>            HasMany(e => e.Notes).Table("notes")
>                          .KeyColumn("id")
>                          .Cascade.All()
>                          .LazyLoad()
>                          .AsSet().Element("note");
>
> Everything works great as far as the mapping goes. However, I cannot
> figure out how to query by the note text using ICriteria.
>
> Let's say I want to find all companies that have notes with text
> "testing 123".
>
> I tried doing a query as follows:
>
> var query = session.CreateCriteria<Company>();
> query.CreateAlias("Notes", "note").Add(Restrictions.Eq("note",
> noteToFind /* a string object */));
> var companeis = query.List();
>
> It says note is not a property of object Company. I cannot do it with
> an inner criteria on the Notes property as well.
>
> Any help would be appreciated.
>
>
> For nitpickers: I know this is not how you search for free text in
> real life. This is just an example with non-actual entity types or
> data.
>
>
>
> --
> 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.

Reply via email to