/// <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); }
/// <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; }