LINQ query - how do you check if the property bag is not null? RRS feed

  • Question

  • I have the code below:

    entity["new_message"] = (string)account.AccountName; is NULL in my case so I am getting a plug-in error.

    • Edited by Sebd.DD Wednesday, October 28, 2015 8:38 AM
    Saturday, October 24, 2015 6:58 PM


All replies

  • Hello,

        What is the plugin error you are getting? I did notice that you have a syntax error in the code you posted. You are missing an ending double-quotes on the following line:

    where accountSet["new_lastname"].Equals("Marcus)

    Hope that helps.

    Saturday, October 24, 2015 8:09 PM
  • Sorry, that was a type here; I have it correct in Visual Studio.

    For instance in the above - I have a record that has the first name but not the last name. It is throwing an error because it cannot do: lastName = accountSet["new_lastname"],

    How do I do something like:

    if (accountSet["new_lastname"] != null)


     lastName = accountSet["new_lastname"],


    • Edited by Sebd.DD Saturday, October 24, 2015 9:13 PM
    Saturday, October 24, 2015 8:12 PM
  • Try something like

    lastName = accountSet.GetAttributeValue<string>("new_lastname");

    Dynamics CRM MVP
    My blog

    Sunday, October 25, 2015 9:05 AM
  • Andrii, that worked thank you! How, nearly all the docs I read said to do it my way. I want to do a little more reading on your method, please can you adsvise on where I could start?
    Sunday, October 25, 2015 9:56 AM
  • Try to download and read SDK. All I know I got there.

    Dynamics CRM MVP
    My blog

    Sunday, October 25, 2015 5:40 PM