Pregunta

¿Cuál sería el código completo para obtener una mejor práctica para obtener una lista con CSOM?

un par de preguntas relacionadas:

  • ¿Deberíamos siempre devolver todas las listas primero y luego ejecutar una consulta LINQ para seleccionar la correcta?
  • ¿Qué propiedad debemos usar para obtener la lista?Me gustaría usar el nombre de la URL (/ MyList /) en lugar del título u GUID, ya que el título (al menos teóricamente) debe ser cambiable y GUID se pone difícil entre entornos (dev / test / qa / on-locales / O365).¿Hay una propiedad para este nombre de URL (sin URL web)
  • ¿El enfoque será el más rápido en la mayoría de los escenarios?

    También me gustaría tener algún razonamiento detrás de la solución propuesta.

¿Fue útil?

Solución

As always it depends.

  • Getting the list by title will give you the best performance as the ListCollection.GetByTitle doesn't even require a trip to the server before you can use the list. But it has the downside that the user can easily change the title and make your code fail.

  • Getting the list by Url or Id will require you to retrieve these properties for all list which require a round trip to the server. Using the Url (relative) will work across sites, but the user has the possibility of moving the list which will then again break your code.

In cases where I can't trust the users not to change things they should leave alone and on the other hand I need to be able to have the code working as stable as possible across sites I've used the approach of:

  • storing Id and Url in a web.property (assume Guid.Empty and default url if nothing is stored)
  • retrieve Id and Url of all lists
  • if any Id match use that list (and update the property if the Url isn't right)
  • if no Id match by an Url does use that list and update Id
  • if no Id nor Url match then cry
Licenciado bajo: CC-BY-SA con atribución
scroll top