How to get id of saved enitity RRS feed

  • Question

  • Dynamics CRM 2011 on premise

    I can barely believe I can't find this out by Googling. MSDN is useless.

    Here is some C# from a plugin:

    integ_creditpayment creditpayment = new integ_creditpayment();
    creditpayment.integ_Amount = totalPay;
    //set more properties

    Now I want to get the value of the id field in integ_creditpayment.

    Can I get this immediately from creditpayment.id? (As in, does context.SaveChanges() cause the creditpayment variable to be updated with the new id?)

    Friday, October 18, 2013 12:21 PM


  • After the SaveChanges() you can get the record id with:
    Guid justCreatedId = creditpayment.Id;

    My blog: www.crmanswers.net

    • Proposed as answer by Guido PreiteMVP Friday, October 18, 2013 12:44 PM
    • Marked as answer by HIMBAPModerator Sunday, October 20, 2013 5:29 PM
    • Unmarked as answer by cja_intgrtch Monday, October 21, 2013 8:20 AM
    • Marked as answer by cja_intgrtch Monday, October 21, 2013 8:28 AM
    Friday, October 18, 2013 12:37 PM