Thanks for the reply but it doesn't work too, it throws a different exception: "cannot dereference scalar collection element: Values". We think that this "special" mapping with a dictionary doesn't allow you to use linq, therefore we are looking to convert it in a plain mapping with a Translation entity and a Translation collection on the Text entity. The bad thing is that this project has no unit testing, it is a big monolith of code, and those "Translation" are used in many places with a lot of hql, for this reason we were looking for a way to not change the mapping, to don't break more the already fragile code.
Am Donnerstag, 6. Juni 2013 18:38:42 UTC+2 schrieb Oskar Berggren: > What about this? > > Session.Query<Example>().Where(e=>e.Text.Translations.Values.Contains( > "Hello")).ToList(); > > > > 2013/6/6 <[email protected] <javascript:>> > >> We have tried to upgrade nhibernate to 3.3 but nothing changed, the linq >> query throws the same exception. >> >> Am Mittwoch, 5. Juni 2013 19:49:16 UTC+2 schrieb Oskar Berggren: >> >>> There are been many improvements to linq support in versions after 3.1. >>> You should try with the latest version (3.3.3). >>> >>> /Oskar >>> >>> >>> 2013/6/5 <[email protected]> >>> >>>> Hello >>>> >>>> We have received an old application to modernize, so we have upgrade >>>> nhibernate to version 3.1 and we have begun to replaced a lot of sql and >>>> hql queries with linq queries but we have a problem with a special >>>> mapping. >>>> The mapping is used to map translations of a text, basically you have a >>>> "Text" table and a "Translation" table, the translation table contains the >>>> text table id, the language code and the translated text. >>>> >>>> The mapping is done with fluent and it maps the "Translation" table to >>>> a dictionary: >>>> >>>> HasMany(x => x.Translations) >>>> .Table("Translation") >>>> .AsMap<int>("LanguageCode") >>>> .Element("Translation") >>>> .KeyColumn("TextId") >>>> .Cascade.AllDeleteOrphan(); >>>> >>>> But if we write linq query to search a translation in the dictionary >>>> like this one: >>>> >>>> Session.Query<Example>().Where**(e=>e.Text.Translations.Any(t=**>t. >>>> Value=="Hello")).ToList(); >>>> >>>> nHibernate throws the following exception: "cannot dereference scalar >>>> collection element: Value" >>>> >>>> The hql query that we want to replace with a linq one is like the >>>> following one: >>>> >>>> Session.CreateQuery("select e from Example e join e.Text.Translations >>>> as translation where translation=:text").SetParamet**er("text","Hello" >>>> ).ToList(); >>>> >>>> Is there a chance to not change the mapping and convert the query from >>>> hql to linq? Or we have to change the mapping and create a "translation" >>>> entity to do it? >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "nhusers" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to nhusers+u...@**googlegroups.com. >>>> To post to this group, send email to [email protected]. >>>> >>>> Visit this group at >>>> http://groups.google.com/**group/nhusers?hl=en-US<http://groups.google.com/group/nhusers?hl=en-US> >>>> . >>>> For more options, visit >>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out> >>>> . >>>> >>>> >>>> >>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "nhusers" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To post to this group, send email to [email protected]<javascript:> >> . >> Visit this group at http://groups.google.com/group/nhusers?hl=en-US. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- You received this message because you are subscribed to the Google Groups "nhusers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/nhusers?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
