コード例 #1
0
        public DynamicEntityDefinition(string entityName, IEnumerable <FieldAttribute> fields, KeyScheme keyScheme)
        {
            var entityAttribute = new EntityAttribute(keyScheme);

            entityAttribute.NameInStore = entityName;

            this.EntityType = typeof(DynamicEntityDefinition);
            this.Initialize(entityAttribute, this.EntityType);
            this.Fields.AddRange(fields);

            var k = this.Fields.FirstOrDefault(c => c.IsPrimaryKey);

            if (k != null)
            {
                this.PrimaryKeyColumnName = k.FieldName;
            }
        }
コード例 #2
0
        public DynamicEntityInfo(string entityName, IEnumerable<FieldAttribute> fields, IEnumerable<ReferenceAttribute> references, KeyScheme keyScheme, EntityInfo.SerializerDelegate serializer, EntityInfo.DeserializerDelegate deserializer)
        {
            this.Registered = false;
            this.AllowRuntimeChanges = DynamicEntityInfo.CanChangeDefinitionsAtRuntime;

            if (entityName == null || entityName.Length <= 0)
                throw new ArgumentException("EntityName", "A DynamicEntityInfo does not accept a null or empty EntityName");

            var entityAttribute = new EntityAttribute(keyScheme);
            entityAttribute.NameInStore = entityName;
            this.EntityType = typeof(DynamicEntityInfo);
            this.Initialize(entityAttribute, this.EntityType);
            this.Serializer = serializer;
            this.Deserializer = deserializer;
            if (fields != null) this.Fields.AddRange(fields);
            if (references != null) this.References.AddRange(references);
        }
コード例 #3
0
        private DynamicEntityDefinition(DynamicEntityDefinition source)
        {
            var entityAttribute = new EntityAttribute(source.EntityAttribute.KeyScheme);

            entityAttribute.NameInStore = source.EntityAttribute.NameInStore;

            this.EntityType = typeof(DynamicEntityDefinition);
            this.Initialize(entityAttribute, this.EntityType);

            // TODO make a copy of these?
            this.Fields.AddRange(source.Fields);

            var k = this.Fields.FirstOrDefault(c => c.IsPrimaryKey);

            if (k != null)
            {
                this.PrimaryKeyColumnName = k.FieldName;
            }
        }
コード例 #4
0
        protected override string GetFieldCreationAttributes(EntityAttribute attribute, FieldAttribute field, Boolean MultiplePrimaryKeys)
        {
            StringBuilder sb = new StringBuilder();

            switch (field.DataType)
            {
            case DbType.AnsiString:
            case DbType.AnsiStringFixedLength:
            case DbType.StringFixedLength:
            case DbType.String:
                if (field.Length > 0)
                {
                    sb.AppendFormat("({0}) ", field.Length);
                }
                else
                {
                    sb.AppendFormat("({0}) ", DefaultStringFieldSize);
                }
                break;

            case DbType.Decimal:
                int p = field.Precision == 0 ? DefaultNumericFieldPrecision : field.Precision;
                sb.AppendFormat("({0},{1}) ", p, field.Scale);
                break;
            }

            if (field.Default != null && field.Default.Length > 0)
            {
                sb.AppendFormat("DEFAULT {0} ", field.Default);
            }

            if (field.IsPrimaryKey)
            {
                if (!MultiplePrimaryKeys)
                {
                    sb.Append("PRIMARY KEY ");
                }

                if (attribute.KeyScheme == KeyScheme.Identity)
                {
                    throw new NotImplementedException();
                    //switch (field.DataType)
                    //{
                    //    case DbType.Int32:
                    //    case DbType.UInt32:
                    //        sb.Append(AutoIncrementFieldIdentifier + " ");
                    //        break;
                    //    case DbType.Guid:
                    //        sb.Append("ROWGUIDCOL ");
                    //        break;
                    //    default:
                    //        throw new FieldDefinitionException(attribute.NameInStore, field.FieldName,
                    //            string.Format("Data Type '{0}' cannot be marked as an Identity field", field.DataType));
                    //}
                }
            }

            if (!field.AllowsNulls)
            {
                sb.Append("NOT NULL ");
            }

            if (field.RequireUniqueValue)
            {
                sb.Append("UNIQUE ");
            }

            return(sb.ToString());
        }
コード例 #5
0
 internal void Initialize(EntityAttribute entityAttribute, Type entityType)
 {
     EntityAttribute = entityAttribute;
     EntityType      = entityType;
 }
コード例 #6
0
 internal void Initialize(EntityAttribute entityAttribute, Type entityType)
 {
     EntityAttribute = entityAttribute;
     EntityType = entityType;
 }