2012/2/8 juanita <[email protected]>: > I have implemented support for a custom user type in my domain model, > but struggle with supporting it in a LINQ where clause. > > For the sake of simplicity, say that the database contains a COLOR > column where a color code is stored as RRGGBB in hex (e.g. FF00FF). > This column is mapped to a custom user type implementing IUserType > with three properties Red,Green,Blue, all integers. > Selecting, updating and inserting data all works fine. There are > plenty of examples for doing this. > > However, what I am struggling with is implementing proper support for > using this type as part of Linq in a where clause. When trying to > lookup an item based on its color, then the linq query would need to > be something like this: > > session.Query<Item>.Where( i => i.Color.Red == 255 && i.Color.Green==0 > && i.Color.Blue==255) > [...] > > Note that merging the three where parts for the individual properties > (red, green, blue) into a single SQL where is highly desirable so that
Given your last statement above, your query should be: session.Query<Item>.Where( i => i.Color == MyColor.For(255, 255, 255)) This should make NHibernate call your IUserType to convert the parameter MyColor instance to whatever format is used in the database. /Oskar -- 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.
