Search code examples
silverlight-4.0mvvmwcf-ria-services

Getting Identity ID from new record in RIA Services


I've seen a lot of articles about retrieving the identity ID of a new created record using other DBs and frameworks. I am creating a record in code in a Silverlight RIA Services app. I perform the Add method and then do a SubmitChanges on the DomainContext, but I do not see the ID. It comes up as 0. How do I get the new ID? Thanks.


Solution

  • Try this

    private void OnProfileCreateCallback(SubmitOperation submitOperation)
            {
              submitOperation.ChangeSet.AddedEntities.First().GetIdentity()
            ....
            }
    

    OnProfileCreateCallback is a call back method used in context.submitchanges(...)

    You can put custom logic if you are having multiple records as part of add.