I am retrieving SPListItems from SPList with a SPQuery that has ViewFields set. I am using ViewFields to improve performance. However, for some items, I need additional data. I know I can just retrieve the single item again with a new query. However, I am wondering, is there a more efficient way that would allow me to just pull the additional fields I need?
views:
29answers:
1
+2
A:
Hi skolima
There is no way to specify that you only want a field included if certain criteria is meet. So Your options are:
- Always get all the fields you need
- Make Multiple queries. Here I'd suggest that you make one for items where you don't need ekstra fields and one for items where you need them instead of starting to do Per Item queries
- If you're on the server use GetItemById to get full SPListItem's for your special items
- Make a calculated field which is empty if criteria is not fulfilled and otherwise is a concatenation of your ekstra fields. You can the include this field in your general Query
Per Jakobsen
2010-07-02 07:43:54
The conditional field inclusion is not exactly what I had in mind, my current scenario is the third possibility you mentioned. I was looking for something like spListItem.LoadAdditionalFields(params string[] fields); :-)
skolima
2010-07-02 11:03:22
How is what you are looking for is different from the above 3rd option, performance-wise the difference is negligible
Vladi Gubler
2010-07-04 05:29:55