PropertyInfo propertyInfo2; //fieldof(DPCollection<RoleDpo>) or fieldof(xxxDpo) #endregion Fields #region Constructors public Mapping(PersistentObject dpo, PropertyInfo propertyInfo2) { this.association = Reflex.GetAssociationAttribute(propertyInfo2); if (association == null) return; this.dpoInstance = dpo; this.propertyInfo2 = propertyInfo2; Type dpoType2; //typeof(RoleDpo) if (propertyInfo2.PropertyType.IsGenericType) { dpoType2 = PersistentObject.GetCollectionGenericType(propertyInfo2); if (this.association.TRelation == null) mappingType = MappingType.One2Many; else mappingType = MappingType.Many2Many; } else { dpoType2 = propertyInfo2.PropertyType; mappingType = MappingType.One2One; } this.propertyInfo1 = dpo.GetType().GetProperty(association.Column1); if (mappingType == MappingType.Many2Many) { this.clause1 = new SqlBuilder() .SELECT.COLUMNS(association.Relation2) .FROM(association.TRelation) .WHERE(association.Relation1.ColumnName() == association.Column1.ParameterName()); this.clause2 = new SqlBuilder() .SELECT .COLUMNS() .FROM(dpoType2) .WHERE(association.Relation2.ColumnName().IN(this.clause1)); } else { SqlExpr where = association.Column2.ColumnName() == association.Column1.ParameterName(); if (association.Filter != null) where = where.AND(association.Filter); this.clause2 = new SqlBuilder() .SELECT .COLUMNS() .FROM(dpoType2) .WHERE(where); if(association.OrderBy != null) this.clause2 = clause2.ORDER_BY(association.OrderBy); } }
public virtual bool Delete() { RowObjectAdapter d = new RowObjectAdapter(this); d.Apply(); //check 1..many table dependency foreach (PropertyInfo propertyInfo in this.columnProperties) { AssociationAttribute association = Reflex.GetAssociationAttribute(propertyInfo); if (association == null) { continue; } if (!propertyInfo.PropertyType.IsGenericType) { continue; } IDPCollection collection = (IDPCollection)propertyInfo.GetValue(this, null); if (collection.Count == 0) { continue; } Type[] typeParameters = propertyInfo.PropertyType.GetGenericArguments(); if (typeParameters.Length == 1 && typeParameters[0].IsSubclassOf(typeof(PersistentObject))) { throw new ApplicationException(string.Format( "Error: data persistent object on Table {0} cannot be deleted because Table {1} depends on it.", TableName, collection.TableName)); } } d.RowChanged += RowChanged; return(d.Delete()); }
private SqlBuilder clause2; //B := SELECT * FROM Roles WHERE Roles.Role_ID IN (A) public Mapping(PersistentObject dpo, PropertyInfo propertyInfo2) { this.association = Reflex.GetAssociationAttribute(propertyInfo2); if (association == null) { return; } this.dpoInstance = dpo; this.propertyInfo2 = propertyInfo2; Type dpoType2; //typeof(RoleDpo) if (propertyInfo2.PropertyType.IsGenericType) { dpoType2 = PersistentObject.GetCollectionGenericType(propertyInfo2); if (this.association.TRelation == null) { mappingType = MappingType.One2Many; } else { mappingType = MappingType.Many2Many; } } else { dpoType2 = propertyInfo2.PropertyType; mappingType = MappingType.One2One; } this.propertyInfo1 = dpo.GetType().GetProperty(association.Column1); if (mappingType == MappingType.Many2Many) { this.clause1 = new SqlBuilder() .SELECT().COLUMNS(association.Relation2) .FROM(association.TRelation) .WHERE(association.Relation1.ColumnName() == association.Column1.ParameterName()); this.clause2 = new SqlBuilder() .SELECT() .COLUMNS() .FROM(dpoType2) .WHERE(association.Relation2.ColumnName().IN(this.clause1)); } else { SqlExpr where = association.Column2.ColumnName() == association.Column1.ParameterName(); if (association.Filter != null) { where = where.AND(association.Filter); } this.clause2 = new SqlBuilder() .SELECT() .COLUMNS() .FROM(dpoType2) .WHERE(where); if (association.OrderBy != null) { this.clause2 = clause2.ORDER_BY(association.OrderBy); } } }