Tuesday, May 31, 2011

TechTalk-Genome: procedure-parameter vs. string-literal problem

We are using TechTalk Genome in our company as an object-relational mapper for C#. Last days i got the requirement to search a xml-tag in an xml-column in our Sql-server database. Unluckily there is no feature in genome to search through the column, so i got to map a RawSql-statement in the mapping file.

So i tried this:
<Member name="HasKey" signature="string" >
    <RawSql source="MyXmlColumn.exist('//Key[text()=&quot{!key-value!}&quot]')=1"/>
</Member>

This doesn't work because genome normally creates a stored procedure for this call and submit my value-string as additional parameter. But the exist() method only accepts string literals, not parameters. After some research i found out, that instead of the exclamation mark ("!") there is a secret sign, the hash-symbol ("#"), which causes Genome to add the value as literal - now the code work's well.

The solution for the parameter problem is the hash-symbol (#), here's the working code:
<Member name="HasKey" signature="string" >
    <RawSql source="MyXmlColumn.exist('//Key[text()=&quot{#key-value#}&quot]')=1"/>
</Member>

No comments: