In CSOM, is there a way to only read a select few properties of an EnterpriseResource? RRS feed

  • Question

  • In every example it seems like they query for the properties of the whole object and then filter from there.

    I really want a way to query for only two properties of the EnterpriseResources. The name and the ID.

    Otherwise, when you make a call to get all the resources it ends up taking 10 or more seconds at around 8000 resources.

    Here is some code that I've been trying to play around with:

    var resourceCollection = projContext.LoadQuery(projContext.EnterpriseResources.Where(x => x.IsGeneric);

    From here I want to add a select statement to the end similar to : .Select(x => x.Name, x => x.Id)

    I tried instantiating a new EnterpriseResource in the Select statement but not quite sure how to. I know it needs a ClientContext and an ObjectPath. I don't know what ObjectPath it wants.

    If selecting only a few properties directly in the query is not possible please let me know.

    Thursday, July 17, 2014 5:44 PM


  • Hi

    You can do that ..

    Here is the sample code to select name and ID

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.ProjectServer.Client;
    using Microsoft.SharePoint.Client;

    namespace ReadResources
        class Program
            private static ProjectContext projContext;
            private const string pwapath = "http://servername/pwa/";
            static void Main(string[] args)
                var resinfo =new EnterpriseResourceCreationInformation();
                projContext = new ProjectContext(pwapath);
                projContext.Load(projContext.EnterpriseResources, nm => nm.Include(ls => ls.Name, ls => ls.Id));
                foreach (EnterpriseResource  rs in projContext.EnterpriseResources)
                  Console.WriteLine("Resource name and ID" + rs.Name + rs.Id);



    --Hope this helps

    Thanks --Ajith

    Friday, July 18, 2014 4:01 PM