locked
Create Entity members using EntityCreateMember RRS feed

  • Question

  • Hi I am trying to add member to an entity using below code. Is there anything wrong with below? It is not getting added.

    private static void CreateEntityMember(string modelName, string versionName, string entityName, string aNewMemberName, string aNewCode, string aNewAddrTypeCode, MemberType memberType, string HierarchyName)
            {

                // Create the request object for entity creation.
                EntityMembersCreateRequest createRequest = new EntityMembersCreateRequest();
                createRequest.Members = new EntityMembers();
                createRequest.ReturnCreatedIdentifiers = true;
                // Set the modelId, versionId, and entityId.
                createRequest.Members.ModelId = new Identifier { Name = modelName };
                createRequest.Members.VersionId = new Identifier { Name = versionName };
                createRequest.Members.EntityId = new Identifier { Name = entityName };
                createRequest.Members.MemberType = memberType;
               
                //member collection
                Collection<ServiceClientRef.Member> membercollection = new Collection<ServiceClientRef.Member>();
                ServiceClientRef.Member aNewMember = new ServiceClientRef.Member();
                aNewMember.MemberId = new MemberIdentifier() { Name = aNewMemberName, Code = aNewCode, MemberType = memberType };
              
                //Attrbiute Collection
                Collection<ServiceClientRef.Attribute> AttrCollection = new Collection<ServiceClientRef.Attribute>();
                ServiceClientRef.Attribute attrCode = new ServiceClientRef.Attribute();
                attrCode.Identifier = new Identifier() { Name = "test" };
                attrCode.Value = aNewCode;
                attrCode.Type = AttributeValueType.String;
                AttrCollection.Add(attrCode);
               
                aNewMember.Attributes = AttrCollection.ToArray();
               
                membercollection.Add(aNewMember);
               
                createRequest.Members.Members = membercollection.ToArray();
               
                Identifier[] colBatches = new Collection<Identifier>().ToArray();
                OperationResult or = new OperationResult();

                MemberIdentifier[] mbs = new MemberIdentifier[] { };
                mbs = clientProxy.EntityMembersCreate(new International(), createRequest.Members, false, out or);


            }

    Friday, October 4, 2013 6:27 AM

Answers

  • Thanks Anup.

    It worked out now. Issue was with the data that is passed.

    Now i have to call this method based on condition on code o any other attribute which would be passed as parameter to another method. If code is new I have to call EntityMembersCreate. If exists it should call EntityMembersUpdate.

    I am looking for something of below: 

    public void Method1 (string Code,string Nm,string AddnAttr1,string AddnAttr2)
    {
    if (<entity>.code ==code)// to update Name and other 2 additional attributes
    call EntityUpdateMembers().....
    else
    call EntityCreateMember().....
    }

    • Marked as answer by Elvis Long Sunday, October 13, 2013 11:26 AM
    Friday, October 4, 2013 1:47 PM

All replies

  • Code works as charm for me.Try to find the reason by checking on below places-

    1. OperationResult(or.Error[] ) for any errors @

     mbs = clientProxy.EntityMembersCreate(new International(), createRequest.Members, false, out or);

    2. Check out MDSLog for operation. check out http://social.msdn.microsoft.com/Forums/sqlserver/en-US/c2e820fd-24cc-4b73-a205-4a0e669985bb/mds-sql-2008-r2-a-database-error-has-occurred-contact-your-system-administrator-when-adding-an?forum=sqlmds for how

    3. Profile the SQL server instance where MDS db is hosted.

    Let me know if this works?



    • Proposed as answer by AnupKumar Monday, October 7, 2013 5:14 AM
    Friday, October 4, 2013 9:12 AM
  • Thanks Anup.

    It worked out now. Issue was with the data that is passed.

    Now i have to call this method based on condition on code o any other attribute which would be passed as parameter to another method. If code is new I have to call EntityMembersCreate. If exists it should call EntityMembersUpdate.

    I am looking for something of below: 

    public void Method1 (string Code,string Nm,string AddnAttr1,string AddnAttr2)
    {
    if (<entity>.code ==code)// to update Name and other 2 additional attributes
    call EntityUpdateMembers().....
    else
    call EntityCreateMember().....
    }

    • Marked as answer by Elvis Long Sunday, October 13, 2013 11:26 AM
    Friday, October 4, 2013 1:47 PM
  • Makes sense now! Never knew you had entity already present in MDS. :) Just an advice if you have large number of entities, consider using EntityMember bulk update. In terms of Performance bulk update way better, I have struggled quite a bit with MDS performance.
    Monday, October 7, 2013 5:11 AM