开发者

Query an xml column from nhibernate 3.0

I have a xml column in one of my entities

I mananged to use a user type and map this column to a property in my entity of type XmlElement.

I was wondering if I could query this object from the code like I do sql with QueryOver?

I found something like this here. But I don't understand exactly how to quer开发者_如何学JAVAy it

Thank you in advance


well, this is how I did it evetually
not the preatiest code
but anyway ...
I combined the queryover with an sql restriction using the underlyingcriteria property
I needed to use a alias for the restriction because of a line in the nhibernate source code that looks for an alias and gets the substring from begining to the alias
If you don't provide an alias obviously it fails

if (tagIds != null && tagIds.Count > 0)
            {
                StringBuilder attrXPath = new StringBuilder();

                for(int counter = 0;counter<tagIds.Count();counter++)
                {
                    attrXPath.Append("@id=\"");
                    attrXPath.Append(tagIds[counter]);
                    attrXPath.Append("\"");
                    if(counter < tagIds.Count() - 1)
                        attrXPath.Append(" or ");
                }

                query.UnderlyingCriteria
                    .Add(Restrictions.Eq(Projections.SqlProjection("tags.exist('/tags/tag[" + attrXPath.ToString() + "]') as XmlRestriction",
                                                                    new string[] { "XmlRestriction" },
                                                                    new IType[] { NHibernateUtil.String}), 1));
            }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜