| Mauro 的个人资料Taming the Jungle照片日志列表 | 帮助 |
|
7月12日 Down with CAMLCAML as used in Microsoft SharePoint is a “XML-based” query/update language. It’s my pet example of XML abuse. Or “just because you can do something it doesn’t mean you should”.
When compared to the SQL, CAML looses big time:
After having to use it to write queries as part of a Sharepoint project, I toyed with the idea of writing a “SQL where-clause” to CAML converter. So I could write a simple, SQL-like WHERE clause and it would generate the corresponding CAML expression. Well, I didn’t need to. My fellow MVP, Carlos Segura Sanz did just that:
So instead of writing this: <Query> <Where> <Or> <And> <Eq> <FieldRef Name="Column1" /> <Value Type="Text">Value1</Value> </Eq> <Eq> <FieldRef Name="Column2" /> <Value Type="Text">Value2</Value> </Eq> </And> <And> <Eq> <FieldRef Name="Column3" /> <Value Type="Integer">10</Value> </Eq> <IsNotNull> <FieldRef Name="Column3" /> </IsNotNull> </And> </Or> </Where> <GroupBy> <FieldRef Name="Column1" /> </GroupBy> <OrderBy> <FieldRef Name="Column1" /> <FieldRef Name="Column2" Ascending="True" /> <FieldRef Name="Column3" Ascending="False" /> </OrderBy></Query> You just write this:
WHERE ((Column1 = "Value1") AND (Column2 = "Value2")) OR ((Column3 = 10)
AND (Column3 <> NULL)) GROUPBY Column1 ORDERBY Column1, Column2 ASC, Column3 DESC He even has a DLL you can use in your projects to do this at runtime!
Thanks, Carlos. |
|
|