If you have a good understanding of expression trees, you might want to try and hook into the query generation part. There are some hooks in re-linq: https://www.re-motion.org/blogs/mix/archive/2011/01/27/re-linq-a-lot-of-new-customizability.aspx I don't know how much of this is exposed all the way down to NH's APIs.
please go to http://groups.google.com/group/re-motion-users for help. HTH, Stefan On Mar 28, 4:27 pm, j gwood <[email protected]> wrote: > We have a class, DelimitedPath, that contains functionality to store > string values that are delimited by a character, such as a namespace. > The class contains functionality to get different nodes of the string, > such as parent values, etc. The default delimiter is '.' but any > other character value can be specified. We have created a user type > that implements ICompositeUserType to store the delimiter as the > first character of the DelimitedPath value in the database, which > helps us parse the string into the individual nodes when retrieving > the value from the database. > > Is there a way to "intercept" the value that the NHibernate.Linq 3.0 > provider uses in a query so that we can add the delimiter character to > the beginning of a string when the DelimitedPath value is used in a > LINQ query? Developers may not know or don't need to know how the > data is stored in the database, so developers may not know what they > need to add the delimiter value to the beginning of any string in a > LINQ query, such as the query below: > > IList<Privilege> privileges = > privilegePersister.Query().Where( > privilege => > > privilege.Resource.Path.Path.StartsWith("Cambridge.Framework").ToList(); > > The Path property of Resource is type DelimitedPath. The > DelimitedPath.Path property returns the entire value as a string, > which comes in handy as .ToString() cannot be used/is not supported in > the above LINQ query. > > From the Resource class: > /// <summary> > /// The namespace of the resource. Size is set to 450, which is the > max size for nvarchar in an index (i.e., unique constraint). > /// </summary> > public virtual DelimitedPath Path > > From the DelimitedPath class: > /// <summary> > /// The delimited path. > /// </summary> > public string Path > { > get > { > if (nodes == null) return null; > return string.Join(delimiter.ToString(), nodes); > } > > } > > The above query is parsed into the following SQL (some select columns > removed for brevity): > > [Class=NHibernate.SQL]: select privilege0_.Id as Id9_, privilege0_. > [Version] as Version2_9_, > privilege0_.[IsAssignable] as IsAssign3_9_, privilege0_.RightId as > RightId9_, > privilege0_.ResourceId as ResourceId9_ > > from Framework.[Privilege] privilege0_, Framework.[Resource] > resource1_ > > where privilege0_.ResourceId=resource1_.Id and (resource1_.[Path] like > (@p0+'%')) > and resource1_.[ResourceHierarchyTypeId]=@p1; > > @p0 = 'Cambridge.Framework' [Type: String (4000)], @p1 = 0 [Type: > Int32 (0)] > > The above query returns zero rows because the data is stored as > follows: > > .Cambridge.Framework > .Cambridge.Framework.Domain > > Querying for "StartsWith(".Cambridge.Framework")" does bring back rows > from the database (as expected). > > Is there a way to intercept the value used in a LINQ query, either > with ICompositeUserType or some other functionality? -- 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.
