views:

29

answers:

1

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?

+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
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
How is what you are looking for is different from the above 3rd option, performance-wise the difference is negligible
Vladi Gubler