locked
Code to get the latest version of an entitiy using wcf? RRS feed

  • Question

  • Hi,

    I am using WCF services to get entities in MDS. I want to get the entities only in the l;atest version. Can you please share code/api asto how to get the latest version of a model in MDS using WCF?

    Thanks

    Thursday, October 30, 2014 7:39 PM

Answers

  • You can use MetadataGet API to get all versions associated with the model and then sort them by CreatedDateTime or

    UpdatedDateTime depending how you define "the latest version" .

    The code would be like :

    var mdGetRequest = new MetadataGetRequest
                    {
                        SearchCriteria =
                        {
                            Models = new Collection<DC.Identifier>()
                            {
                                new DC.Identifier() {Name = "Account"}
                            },
                        },
                        ResultOptions = {Versions = DC.ResultType.Identifiers},
                    };
                    // Call MDS service
                    MetadataGetResponse mdGetResponse = MyServicesApiUtility.MdsService.MetadataGet(mdGetRequest);
                    if (mdGetResponse.OperationResult.Errors.Count == 0 && mdGetResponse.Metadata.Versions.Count != 0)
                    {
                        var versions =  new List<DC.Version>(mdGetResponse.Metadata.Versions);
                        versions.Sort(
                            (ver1, ver2) => ver2.AuditInfo.CreatedDateTime.CompareTo(ver1.AuditInfo.CreatedDateTime));
                        return versions.First();
                                        }
                    else
                    {
                        throw new Exception(string.Format("No version related to model {0}.", "Account"));
                    }

    Thursday, November 20, 2014 8:29 PM

All replies

  • Does anyone have a suggestion for Hardy?

    Thanks!


    Ed Price, Azure & Power BI Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Saturday, November 15, 2014 7:23 AM
  • You can use MetadataGet API to get all versions associated with the model and then sort them by CreatedDateTime or

    UpdatedDateTime depending how you define "the latest version" .

    The code would be like :

    var mdGetRequest = new MetadataGetRequest
                    {
                        SearchCriteria =
                        {
                            Models = new Collection<DC.Identifier>()
                            {
                                new DC.Identifier() {Name = "Account"}
                            },
                        },
                        ResultOptions = {Versions = DC.ResultType.Identifiers},
                    };
                    // Call MDS service
                    MetadataGetResponse mdGetResponse = MyServicesApiUtility.MdsService.MetadataGet(mdGetRequest);
                    if (mdGetResponse.OperationResult.Errors.Count == 0 && mdGetResponse.Metadata.Versions.Count != 0)
                    {
                        var versions =  new List<DC.Version>(mdGetResponse.Metadata.Versions);
                        versions.Sort(
                            (ver1, ver2) => ver2.AuditInfo.CreatedDateTime.CompareTo(ver1.AuditInfo.CreatedDateTime));
                        return versions.First();
                                        }
                    else
                    {
                        throw new Exception(string.Format("No version related to model {0}.", "Account"));
                    }

    Thursday, November 20, 2014 8:29 PM