Пример #1
0
        public ExtendedPropertyDefinition CreateProperty(EntityType entityType, string name, string nativeName, ExtendedPropertyDataType dataType,
                                                         long size, bool multiValue)
        {
            if (entityType == null)
            {
                throw new ArgumentNullException("entityType");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw new ArgumentOutOfRangeException("'name' is zero-length.");
            }
            if (nativeName == null)
            {
                throw new ArgumentNullException("nativeName");
            }
            if (nativeName.Length == 0)
            {
                throw new ArgumentOutOfRangeException("'nativeName' is zero-length.");
            }
            if (nativeName.Length > DatabaseExtensibilityProvider.MaxNativeNameLength)
            {
                throw new ArgumentException(string.Format("Native name '{0}' is {1} characters in length and the maximum is {2} characters.", nativeName,
                                                          nativeName.Length, DatabaseExtensibilityProvider.MaxNativeNameLength));
            }
            if (dataType == null)
            {
                throw new ArgumentNullException("dataType");
            }

            // mbr - 25-09-2007 - check with provider...
            if (Database.ExtensibilityProvider == null)
            {
                throw new InvalidOperationException("Database.ExtensibilityProvider is null.");
            }
            Database.ExtensibilityProvider.AssertDefinition(entityType, name, nativeName, dataType, size, multiValue);

            // is it a legal name?
            EntityType.AssertIsLegalIdentifierName(nativeName);

            // do we already have it?
            ExtendedPropertyDefinition existing = this.Properties[entityType.Id, nativeName];

            if (existing != null)
            {
                throw new InvalidOperationException(string.Format("'{0}' already has a property called '{1}' (name).", entityType.Name, nativeName));
            }

            // mbr - 12-12-2005 - other check for the display name...
            existing = this.Properties.GetByName(entityType.Id, name, false);
            if (existing != null)
            {
                throw new InvalidOperationException(string.Format("'{0}' already has a property called '{1}' (display name).", entityType.Name, name));
            }

            // create it...
            ExtendedPropertyDefinition prop = new ExtendedPropertyDefinition(name, nativeName, dataType, entityType.Id);

            prop.Size = size;

            // check...
            if (dataType.SupportsMultiValue && multiValue)
            {
                prop.MultiValue = true;
            }
            else
            {
                prop.MultiValue = false;
            }

            // add...
            this.Properties.Add(prop);

            // mbr - 02-10-2007 - for c7 - we don't want to do this here because it will frankly take too
            // long.  do it later...
//			EnsureExtendedTableUpToDate(entityType);

            // return...
            return(prop);
        }