Пример #1
0
 /// <summary>
 /// Cria uma instancia para propriedade mapeada.
 /// </summary>
 /// <param name="modelType"></param>
 /// <param name="ppa"></param>
 /// <param name="propertyMapper"></param>
 public Mapper(Type modelType, PersistencePropertyAttribute ppa, PropertyInfo propertyMapper)
 {
     this._modelType          = modelType;
     this._name               = ppa.Name;
     this._direction          = ppa.Direction;
     this._parameterType      = ppa.ParameterType;
     this._size               = ppa.Size;
     this._propertyMapper     = propertyMapper;
     this._propertyMapperName = propertyMapper.Name;
     this._generatorKeyName   = ppa.GeneratorKeyName;
     this._isNotNull          = ppa.IsNotNull;
 }
Пример #2
0
        /// <summary>
        /// Recupera no nome da campo da BD que a propriedade representa.
        /// </summary>
        /// <typeparam name="Model">Tipo da class que contem a propriedade.</typeparam>
        /// <param name="propertyName">Nome da propriedade.</param>
        /// <returns>Nome do campo da BD.</returns>
        public static string GetPropertyDBFieldName <Model>(string propertyName)
        {
            Type         persistenceType = typeof(Model);
            PropertyInfo pi = persistenceType.GetProperty(propertyName);

            if (pi == null)
            {
                throw new GDAException("Property {0} not found in {1}", propertyName, persistenceType.FullName);
            }
            PersistencePropertyAttribute ppa = MappingManager.GetPersistenceProperty(pi);

            if (ppa == null)
            {
                throw new GDAException("DBFieldName not found in Property {0}.", propertyName);
            }
            return(ppa.Name);
        }
Пример #3
0
        /// <summary>
        /// Carrega a consulta sql da tabela filha tem como base os relacionamento entre ela e a atual model, que s�o
        /// identificados pelo atributos <see cref="PersistenceForeignKeyAttribute"/>.
        /// </summary>
        /// <typeparam name="ClassChild">Tipo da classe que representa a tabela filha.</typeparam>
        /// <param name="parentObj">Objeto contendo as informa��es para fazer o relacionamento.</param>
        /// <param name="groupOfRelationship">Nome do grupo de relacionamento.</param>
        /// <param name="dao">DAO relacionada a classe filha.</param>
        /// <param name="sql">Consulta sql do relacionamento.</param>
        /// <param name="parametersWhere">Par�metros gerados.</param>
        private static void MakeSqlForeignKeyParentToChild <ClassChild>(Model parentObj, string groupOfRelationship, IBaseDAO <ClassChild> dao, out string sql, out List <GDAParameter> parametersWhere, IProvider provider) where ClassChild : new()
        {
            Type typeOfClassChild             = typeof(ClassChild);
            Type typeModel                    = typeof(Model);
            GroupOfRelationshipInfo groupInfo = new GroupOfRelationshipInfo(typeOfClassChild, typeModel, groupOfRelationship);
            List <ForeignKeyMapper> mapper    = MappingManager.LoadRelationships(typeOfClassChild, groupInfo);

            if (mapper.Count == 0)
            {
                throw new GDAException("ForeignKey " + groupInfo.ToString() + " not found in " + typeof(Model).FullName);
            }
            parametersWhere = new List <GDAParameter>();
            string tableNameRelated = provider.BuildTableName(MappingManager.GetTableName(typeOfClassChild));

            sql          = String.Format("SELECT * FROM {0} ", tableNameRelated);
            string where = "";
            foreach (ForeignKeyMapper fk in mapper)
            {
                PersistencePropertyAttribute ppaTbl1 = MappingManager.GetPersistenceProperty(fk.PropertyOfClassRelated);
                PersistencePropertyAttribute ppaTbl2 = MappingManager.GetPersistenceProperty(fk.PropertyModel);
                if (ppaTbl1 == null)
                {
                    throw new GDAException("PersistencePropertyAttribute not found in property {0}", fk.PropertyOfClassRelated.Name);
                }
                if (ppaTbl2 == null)
                {
                    throw new GDAException("PersistencePropertyAttribute not found in property {0}", fk.PropertyModel.Name);
                }
                parametersWhere.Add(new GDAParameter("?" + ppaTbl1.Name.Replace(" ", "_"), fk.PropertyOfClassRelated.GetValue(parentObj, null)));
                if (where != "")
                {
                    where += " AND ";
                }
                where += String.Format("{0}=?{1}", provider.QuoteExpression(ppaTbl1.Name), ppaTbl1.Name.Replace(" ", "_"));
            }
            sql += " WHERE " + where;
        }