Creating SharePoint 2010 external content types programmatically

In this code sample I provide an extension to the standard SharePoint Business Conectivity Services admin API that helps to create external content types and the related external lists using client side APIs. A console application is used to illustrate the usage of the extension.

C# (40.6 KB)
 
 
 
 
 
3.8 Star
(4)
2,178 times
Add to favorites
3/10/2011
E-mail Twitter del.icio.us Digg Facebook
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.BusinessData.MetadataModel;
using Microsoft.SharePoint.BusinessData.Administration.Client;

namespace BCSModelGeneration
{

    public class TypeDescriptorParams
    {
        private String _name;
        private bool _isNameSpecified = false;
        public String Name { get
        {
            return _name;
        }
            set
            {
                _isNameSpecified = true;
                _name = value; 
            }
        }

        private bool _isCached;
        private bool _isIsCachedSpecified = false;
        public bool IsCached
        {
            get
            {
                return _isCached;
            }
            set
            {
                _isIsCachedSpecified = true;
                _isCached = value;
            }
        }

        private Type _type;
        private bool _isTypeSpecified = false;
        public Type Type
        {
            get
            {
                return _type;
            }
            set
            {
                _isTypeSpecified = true;
                _type = value;
            }
        }

        private String _lobName;
        private bool _isLobNameSpecified = false;
        public String LobName
        {
            get
            {
                return _lobName;
            }
            set
            {
                _isLobNameSpecified = true;
                _lobName = value;
            }
        }

        private IdentifierReference _identifierReference;
        private bool _isIdentifierReferenceSpecified = false;
        public IdentifierReference IdentifierReference
        {
            get
            {
                return _identifierReference;
            }
            set
            {
                _isIdentifierReferenceSpecified = true;
                _identifierReference = value;
            }
        }

        private FilterDescriptor _filterDescriptor;
        private bool _isFilterDescriptorSpecified = false;
        public FilterDescriptor FilterDescriptor
        {
            get
            {
                return _filterDescriptor;
            }
            set
            {
                _isFilterDescriptorSpecified = true;
                _filterDescriptor = value;
            }
        }

        private TypeDescriptorFlags _flags;
        private bool _isFlagsSpecified = false;
        public TypeDescriptorFlags Flags
        {
            get
            {
                return _flags;
            }
            set
            {
                _isFlagsSpecified = true;
                _flags = value;
            }
        }        

        private AssociationReference _associationReference;
        private bool _isAssociationReferenceSpecified = false;
        public AssociationReference AssociationReference
        {
            get
            {
                return _associationReference;
            }
            set
            {
                _isAssociationReferenceSpecified = true;
                _associationReference = value;
            }
        }

        private AdministrationMetadataCatalog _metadataCatalog;
        private bool _isMetadataCatalogSpecified = false;
        public AdministrationMetadataCatalog MetadataCatalog
        {
            get
            {
                return _metadataCatalog;
            }
            set
            {
                _isMetadataCatalogSpecified = true;
                _metadataCatalog = value;
            }
        }

        public TypeDescriptorParams()
        {
        }

        public TypeDescriptorParams(TypeDescriptorParams explicitParams)
        {
            if (explicitParams._isNameSpecified) this.Name = explicitParams.Name;
            if (explicitParams._isIsCachedSpecified) this.IsCached = explicitParams.IsCached;
            if (explicitParams._isTypeSpecified) this.Type = explicitParams.Type;
            if (explicitParams._isLobNameSpecified) this.LobName = explicitParams.LobName;
            if (explicitParams._isIdentifierReferenceSpecified) this.IdentifierReference = explicitParams.IdentifierReference;
            if (explicitParams._isFilterDescriptorSpecified) this.FilterDescriptor = explicitParams.FilterDescriptor;
            if (explicitParams._isFlagsSpecified) this.Flags = explicitParams.Flags;
            if (explicitParams._isAssociationReferenceSpecified) this.AssociationReference = explicitParams.AssociationReference;
            if (explicitParams._isMetadataCatalogSpecified) this.MetadataCatalog = explicitParams.MetadataCatalog;
        }

        public void ResolveNames()
        {
            // names default to the other name type
            if ((this._isNameSpecified) && (!this._isLobNameSpecified))
            {
                this.LobName = this.Name;
            }

            if ((!this._isNameSpecified) && (this._isLobNameSpecified))
            {
                this.Name = this.LobName;
            }
        }
    }
}