Esempio n. 1
0
        internal static string PrintUnsavedValue(this PrimaryKeyProperty property)
        {
            string rVal = null;

            if (!string.IsNullOrWhiteSpace(property.UnsavedValueString))
            {
                var dbType = property.Key.DbType;
                switch (dbType)
                {
                case DbType.Decimal:
                case DbType.Double:
                case DbType.Int16:
                case DbType.Int32:
                case DbType.Int64:
                case DbType.VarNumeric:
                case DbType.UInt64:
                case DbType.UInt32:
                case DbType.UInt16:
                    rVal = property.UnsavedValueString;
                    break;

                case DbType.Guid:
                    rVal = string.Format("new Guid(\"{0}\")", property.UnsavedValueString);
                    break;

                default:
                    rVal = string.Format("\"{0}\"", property.UnsavedValueString);
                    break;
                }
            }

            return(rVal);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds the key.
        /// </summary>
        /// <param name="key">The key.</param>
        public void AddKey(PrimaryKeyProperty key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            if (PrimaryKey == null)
            {
                PrimaryKey = new PrimaryKey();
            }

            PrimaryKey.Keys.Add(key);
            AllProperties.Add(key.Key);
        }
Esempio n. 3
0
            void ElementEntityPrimaryKey(XmlReader reader, MapConfig config, EntityMap entMap)
            {
                bool hasReachedEndGracefully   = false;
                List <PrimaryKeyProperty> keys = new List <PrimaryKeyProperty>();

                while (reader.Read())
                {
                    if (reader.CanReadElement("key"))
                    {
                        PrimaryKeyProperty pk = new PrimaryKeyProperty();
                        var prop = Read_PropertyElement(reader, config, "key", pk);
                        if (prop != null)
                        {
                            pk.Key = prop;
                            IKeyGenerator idGenerator;
                            if (!string.IsNullOrWhiteSpace(pk.KeyGenerationStrategy) && config.PrimaryKeyGeneratorStore.TryGetValue(pk.KeyGenerationStrategy, out idGenerator))
                            {
                                pk.KeyGenerator = idGenerator;
                            }
                            keys.Add(pk);
                        }
                    }
                    else if (reader.HasReachedEndOfElement("primaryKey"))
                    {
                        hasReachedEndGracefully = true;
                        break;
                    }
                }

                if (!hasReachedEndGracefully)
                {
                    throw new MappingSerializationException(typeof(PrimaryKey), "missing a </primaryKey> end tag");
                }

                entMap.AddKeyRange(keys);
            }
Esempio n. 4
0
            Property Read_PropertyElement(XmlReader reader, MapConfig config, string elementName, PrimaryKeyProperty pk, bool forceReturnRel = false)
            {
                if (reader.CanReadElement(elementName))
                {
                    var    property     = new Property();
                    var    rel          = new Relation();
                    bool   loadedRel    = false;
                    string keyGen       = null;
                    string unsavedValue = null;

                    while (reader.MoveToNextAttribute())
                    {
                        string currentAttribute = reader.Name;
                        switch (currentAttribute)
                        {
                        case "name":
                            property.PropertyName = reader.Value;
                            break;

                        case "column":
                            property.ColumnName = reader.Value;
                            break;

                        case "constraintType":
                            property.ConstraintType = ReadEnumType <ConstraintType>(reader.Value);
                            break;

                        case "clrType":
                            //property.ClrType = ReadClrType(reader.Value);
                            break;

                        case "dbType":
                            property.DbType = ReadEnumType <System.Data.DbType>(reader.Value);
                            break;

                        case "sqlType":
                            property.SqlType = reader.Value;
                            break;

                        case "length":
                            property.Length = ReadInteger(reader.Value);
                            break;

                        case "precision":
                            property.Precision = ReadInteger(reader.Value);
                            break;

                        case "scale":
                            property.Scale = ReadInteger(reader.Value);
                            break;

                        case "type":
                            property.ComplexTypeName = reader.Value;
                            property.IsComplexType   = true;
                            break;

                        case "lazy":
                            property.LazyLoad = ReadBool(reader.Value);
                            break;

                        case "unique":
                            property.IsUnique = ReadBool(reader.Value);
                            break;

                        case "primaryKey":
                            property.IsPrimaryKey = ReadBool(reader.Value);
                            break;

                        case "default":
                            property.DefaultValue = reader.Value;
                            break;

                        case "constraint":
                            property.ConstraintName = reader.Value;
                            break;

                        case "ignoreOnUpdate":
                            property.IgnoreOnUpdate = ReadBool(reader.Value);
                            break;

                        case "nullable":
                            property.IsNullable = ReadBool(reader.Value);
                            break;

                        case "identity":
                            property.IsIdentity = ReadBool(reader.Value);
                            break;

                        case "autoGenerated":
                            property.IsAutoGenerated = ReadBool(reader.Value);
                            break;

                        case "order":
                            property.Order = ReadInteger(reader.Value);
                            break;

                        //relation attributes
                        case "relation":
                            loadedRel        = true;
                            rel.RelationType = ReadEnumType <RelationshipType>(reader.Value);
                            break;

                        case "referenceTable":
                            loadedRel          = true;
                            rel.ReferenceTable = reader.Value;
                            break;

                        case "referenceColumn":
                            loadedRel           = true;
                            rel.ReferenceColumn = reader.Value;
                            break;

                        case "referenceProperty":
                            loadedRel             = true;
                            rel.ReferenceProperty = reader.Value;
                            break;

                        case "refConstraint":
                            loadedRel = true;
                            rel.ReferenceConstraintName = reader.Value;
                            break;

                        case "refEntity":
                            loadedRel = true;
                            rel.ReferenceEntityName = reader.Value;
                            break;

                        case "exclude":
                            loadedRel   = true;
                            rel.Exclude = ReadBool(reader.Value);
                            break;

                        case "inverse":
                            loadedRel   = true;
                            rel.Inverse = ReadBool(reader.Value);
                            break;

                        case "mapColumn":
                            loadedRel     = true;
                            rel.MapColumn = reader.Value;
                            break;

                        case "mapReferenceColumn":
                            loadedRel = true;
                            rel.MapReferenceColumn = reader.Value;
                            break;

                        case "manyToManyPropertyName":
                            loadedRel = true;
                            rel.ManyToManyPropertyName = reader.Value;
                            break;

                        case "propertyName":
                            loadedRel           = true;
                            rel.MapPropertyName = reader.Value;
                            break;

                        case "mapTable":
                            loadedRel        = true;
                            rel.MapTableName = reader.Value;
                            break;

                        //primary key attributes
                        case "unsaved_value":
                            unsavedValue = reader.Value;
                            break;

                        case "key_generator":
                            keyGen = reader.Value;
                            break;

                        default:
                            if (includeMetaData)
                            {
                                if (!string.IsNullOrWhiteSpace(currentAttribute) && currentAttribute.StartsWith("data_"))
                                {
                                    string metaKey = currentAttribute.Replace("data_", string.Empty);
                                    if (!property.MetaDataAttributes.ContainsKey(metaKey))
                                    {
                                        property.MetaDataAttributes.Add(metaKey, reader.Value);
                                    }
                                }
                            }
                            break;
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(elementName) && elementName.Equals("key", StringComparison.OrdinalIgnoreCase) &&
                        pk != null)
                    {
                        pk.KeyGenerationStrategy = keyGen;
                        pk.UnsavedValueString    = unsavedValue;
                    }

                    if (loadedRel)
                    {
                        rel.LoadPropertyValues(property);
                        return(rel);
                    }

                    if (forceReturnRel)
                    {
                        rel = new Relation(property);
                        return(rel);
                    }

                    return(property);
                }
                return(null);
            }