CRM 2011 SDK statecode/statuscode returns null values RRS feed

  • Question

  • I'm retrieving a custom entity using the latest SDK with a linq statement.

    I'm using early binding and my XrmServiceContent was created with the crmsvcutil program.

    I'm attempting to retrieve all of my inactive custom entities:

    var test = xrm.dt_jobsiteSet.Where(j => j.statecode == 1).Select(j => new { Name = j.dt_jobsiteprojectname, StateCode = j.statecode}).ToList();

    var test1 = xrm.dt_jobsiteSet.Where(j => j.statuscode == 2).Select(j => new { Name = j.dt_jobsiteprojectname, StatusCode = j.statuscode}).ToList();

    test & test1 returns the correct results, but the StateCode & StatusCode values are all null.

    Do these attributes need to be "converted"? I'm sure it's something basic - just need another set of eyes to identify my problem!

    TIA - Bob

    Friday, May 18, 2012 4:04 PM


  • Found the answer.

    It has do with the way the crm linq pulls down data from the on line server and caches them for performance.

    Just prior to my running the two select statements above (test & test1), I had already done a previous select statement to the same custom entity. In that previous select statement, the statecode and statuscode attributes were NOT being requested, so by default, the values are set to null. Once I added these two attributes to the original select statement, the values were properly set for my subsequent selects.

    • Marked as answer by Bob Titular Friday, May 18, 2012 4:51 PM
    Friday, May 18, 2012 4:50 PM