コード例 #1
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            switch (this.ParameterSetName)
            {
            case AddEntityKeyParameterSet:
                EntityKeyMetadata key = new EntityKeyMetadata()
                {
                    LogicalName = Name,
                    SchemaName  = Name,
                    DisplayName = new Label(DisplayName, CrmContext.Language)
                };
                key.KeyAttributes = Attributes;
                if (!string.IsNullOrWhiteSpace(SchemaName))
                {
                    key.SchemaName = SchemaName;
                }

                Guid id1 = _repository.AddEntityKey(Entity, key);
                if (PassThru)
                {
                    WriteObject(_repository.GetEntityKey(id1));
                }
                break;

            case AddEntityKeyByInputObjectParameterSet:
                Guid id2 = _repository.AddEntityKey(Entity, InputObject);
                if (PassThru)
                {
                    WriteObject(_repository.GetEntityKey(id2));
                }
                break;

            default:
                break;
            }
        }