Example #1
0
        private void BuildCommand(MySqlCommand cmd, Type typeToBuild, string primaryKeyValue)
        {
            PersistentClass      persistentClassAttribute = (PersistentClass)typeToBuild.GetCustomAttributes(typeof(PersistentClass), false).Single();
            PropertyInfo         primaryKeyPropertyInfo   = typeToBuild.GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(PersistentPrimaryKeyProperty))).Single();
            StringPropertyBridge primaryKeyPropertyBridge = new StringPropertyBridge(primaryKeyPropertyInfo, primaryKeyValue);

            primaryKeyPropertyBridge.SetSqlParameter(cmd);
            cmd.CommandText += "Select * from " + persistentClassAttribute.StorageName + " where " + primaryKeyPropertyInfo.Name + " = " + primaryKeyPropertyBridge.AtName + "; ";

            this.BuildPersistentChildCollectionCommands(typeToBuild, cmd);
        }
        private void BuildCommand(SqlCommand cmd, Type typeToBuild, string primaryKeyValue)
        {
            PersistentClass persistentClassAttribute = (PersistentClass)typeToBuild.GetCustomAttributes(typeof(PersistentClass), false).Single();
            PropertyInfo primaryKeyPropertyInfo = typeToBuild.GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(PersistentPrimaryKeyProperty))).Single();
            StringPropertyBridge primaryKeyPropertyBridge = new StringPropertyBridge(primaryKeyPropertyInfo, primaryKeyValue);

            primaryKeyPropertyBridge.SetSqlParameter(cmd);
            cmd.CommandText += "Select * from " + persistentClassAttribute.StorageName + " where " + primaryKeyPropertyInfo.Name + " = " + primaryKeyPropertyBridge.AtName + "; ";

            this.BuildPersistentChildCollectionCommands(typeToBuild, cmd);
        }
        public static PropertyBridge GetPropertyBridge(PropertyInfo property, object obj)
        {
            PropertyBridge propertyBridge = null;

            if (property.PropertyType.Name == typeof(string).Name)
            {
                propertyBridge = new StringPropertyBridge(property, obj);
            }
            else if (property.PropertyType.Name == typeof(bool).Name)
            {
                propertyBridge = new BooleanPropertyBridge(property, obj);
            }
            else if (property.PropertyType.Name == typeof(int).Name)
            {
                propertyBridge = new IntPropertyBridge(property, obj);
            }
            else if (property.PropertyType.Name == typeof(double).Name)
            {
                propertyBridge = new DoublePropertyBridge(property, obj);
            }
            else if (property.PropertyType.Name == typeof(DateTime).Name)
            {
                propertyBridge = new DateTimePropertyBridge(property, obj);
            }
            else if (property.PropertyType.IsGenericType)
            {
                Type genericTypeDef = property.PropertyType.UnderlyingSystemType;
                if (genericTypeDef == typeof(Nullable <DateTime>))
                {
                    propertyBridge = new DateTimePropertyBridge(property, obj);
                }
                else if (genericTypeDef == typeof(Nullable <int>))
                {
                    propertyBridge = new IntPropertyBridge(property, obj);
                }
                else if (genericTypeDef == typeof(Nullable <double>))
                {
                    propertyBridge = new DoublePropertyBridge(property, obj);
                }
                else if (genericTypeDef == typeof(Nullable <bool>))
                {
                    propertyBridge = new IntPropertyBridge(property, obj);
                }
            }
            else
            {
                throw new Exception("This data type not implemented in the Property Bridge Factory");
            }
            return(propertyBridge);
        }
 public static PropertyBridge GetPropertyBridge(PropertyInfo property, object obj)
 {
     PropertyBridge propertyBridge = null;
     if (property.PropertyType.Name == typeof(string).Name)
     {
         propertyBridge = new StringPropertyBridge(property, obj);
     }
     else if (property.PropertyType.Name == typeof(bool).Name)
     {
         propertyBridge = new BooleanPropertyBridge(property, obj);
     }
     else if (property.PropertyType.Name == typeof(int).Name)
     {
         propertyBridge = new IntPropertyBridge(property, obj);
     }
     else if (property.PropertyType.Name == typeof(double).Name)
     {
         propertyBridge = new DoublePropertyBridge(property, obj);
     }
     else if (property.PropertyType.Name == typeof(DateTime).Name)
     {
         propertyBridge = new DateTimePropertyBridge(property, obj);
     }
     else if (property.PropertyType.IsGenericType)
     {
         Type genericTypeDef = property.PropertyType.UnderlyingSystemType;
         if (genericTypeDef == typeof(Nullable<DateTime>))
         {
             propertyBridge = new DateTimePropertyBridge(property, obj);
         }
         else if (genericTypeDef == typeof(Nullable<int>))
         {
             propertyBridge = new IntPropertyBridge(property, obj);
         }
         else if (genericTypeDef == typeof(Nullable<double>))
         {
             propertyBridge = new DoublePropertyBridge(property, obj);
         }
         else if (genericTypeDef == typeof(Nullable<bool>))
         {
             propertyBridge = new IntPropertyBridge(property, obj);
         }
     }
     else
     {
         throw new Exception("This data type not implemented in the Property Bridge Factory");
     }
     return propertyBridge;
 }
        public SqlCommand Build()
        {
            SqlCommand cmd = new SqlCommand();
            PersistentClass persistentClassAttribute = (PersistentClass)this.m_Type.GetCustomAttributes(typeof(PersistentClass), false).Single();

            PropertyInfo primaryKeyPropertyInfo = this.m_Type.GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(PersistentPrimaryKeyProperty))).Single();
            StringPropertyBridge primaryKeyPropertyBridge = new StringPropertyBridge(primaryKeyPropertyInfo, this.m_PrimaryKeyValue);
            primaryKeyPropertyBridge.SetSqlParameter(cmd);

            SqlSelectClause sqlSelect = new SqlSelectClause(this.m_Type);

            SqlParameterClause sqlParameterStatement = new SqlParameterClause(this.m_Type, this.m_PrimaryKeyValue);
            SqlStatement sqlStatement = new SqlStatement(sqlParameterStatement, sqlSelect, this.m_Type);

            cmd.CommandText = sqlStatement.ToString();
            return cmd;
        }
Example #6
0
        public SqlCommand Build()
        {
            SqlCommand      cmd = new SqlCommand();
            PersistentClass persistentClassAttribute = (PersistentClass)this.m_Type.GetCustomAttributes(typeof(PersistentClass), false).Single();

            PropertyInfo         primaryKeyPropertyInfo   = this.m_Type.GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(PersistentPrimaryKeyProperty))).Single();
            StringPropertyBridge primaryKeyPropertyBridge = new StringPropertyBridge(primaryKeyPropertyInfo, this.m_PrimaryKeyValue);

            primaryKeyPropertyBridge.SetSqlParameter(cmd);

            SqlSelectClause sqlSelect = new SqlSelectClause(this.m_Type);

            SqlParameterClause sqlParameterStatement = new SqlParameterClause(this.m_Type, this.m_PrimaryKeyValue);
            SqlStatement       sqlStatement          = new SqlStatement(sqlParameterStatement, sqlSelect, this.m_Type);

            cmd.CommandText = sqlStatement.ToString();
            return(cmd);
        }