private void ParseRelation(EntityMap entity, XmlNode attributeNode, string defaultNamespace) { Relationship relationship; switch (this.GetValue(attributeNode, "relationship").ToUpper()) { case "ONETOMANY": relationship = Relationship.Child; break; case "MANYTOONE": relationship = Relationship.Parent; break; case "MANYTOMANY": relationship = Relationship.Many; break; default: throw new MappingException("Mapping: Relation relationship is Invalid"); } string member = this.GetValue(attributeNode, "member"); string field = this.GetValue(attributeNode, "field"); string type = this.GetNamespacedValue(attributeNode, "type", defaultNamespace); // Jeff Lanning ([email protected]): Added optional "alias" attribute for use in OPath queries (and to help code generators build entity classes) string alias = this.GetValue(attributeNode, "alias", member); // optional queryOnly is used to enable OPath on relationships without actually loading any relationships -- no member allowed, alias is required bool queryOnly; // Default queryOnly is False switch (this.GetValue(attributeNode, "queryOnly", "FALSE").ToUpper()) { case "TRUE": queryOnly = true; break; default: queryOnly = false; break; } if (!queryOnly) { if (member == null || member.Length == 0) { throw new MappingException("Mapping: Relation attribute 'member' must be specified when 'queryOnly' is set to false - " + entity.Type + " : " + member); } } else { if (member != null && member.Length > 0) { throw new MappingException("Mapping: Relation attribute 'member' is not allowed when 'queryOnly' is set to true - " + entity.Type + " : " + member); } if (alias == null || alias.Length == 0) { throw new MappingException("Mapping: Relation attribute 'alias' must be specified when queryOnly is set to true - " + entity.Type + " : " + type); } member = alias; // Required internally for hashtables, but would be inconsistent if allowed externally } bool lazyLoad; // Default lazyLoad is True switch (this.GetValue(attributeNode, "lazyLoad", "TRUE").ToUpper()) { case "FALSE": lazyLoad = false; break; default: lazyLoad = true; break; } // CascadeDelete help from Ken Muse (http://www.MomentsFromImpact.com) bool cascadeDelete; // Default cascaseDelete is False switch (this.GetValue(attributeNode, "cascadeDelete", "FALSE").ToUpper()) { case "TRUE": cascadeDelete = true; break; default: cascadeDelete = false; break; } string filter = this.GetValue(attributeNode, "filter"); string selectSP = this.GetValue(attributeNode, "selectSP"); if (relationship == Relationship.Child) { entity.AddChild(member, field, type, alias, queryOnly, lazyLoad, cascadeDelete, filter, selectSP, this.provider); } else if (relationship == Relationship.Parent) { entity.AddParent(member, field, type, alias, queryOnly, lazyLoad, cascadeDelete, filter, selectSP, this.provider); } else { string table = this.GetValue(attributeNode, "table"); string source = this.GetValue(attributeNode, "sourceField"); string dest = this.GetValue(attributeNode, "destField"); string insertSP = this.GetValue(attributeNode, "insertSP"); string deleteSP = this.GetValue(attributeNode, "deleteSP"); entity.AddMany(member, field, type, alias, table, source, dest, queryOnly, lazyLoad, cascadeDelete, filter, selectSP, insertSP, deleteSP, this.provider); } }
private void ParseRelation(EntityMap entity, XmlNode attributeNode, string defaultNamespace, string defaultSchema) { Relationship relationship; switch (this.GetValue(attributeNode, "relationship").ToUpper()) { case "ONETOMANY": relationship = Relationship.Child; break; case "MANYTOONE": relationship = Relationship.Parent; break; case "MANYTOMANY": relationship = Relationship.Many; break; default: throw new MappingException("Mapping: Relation relationship is Invalid"); } string member = this.GetValue(attributeNode, "member"); string field = this.GetValue(attributeNode, "field"); string type = this.GetTypeName(attributeNode, "type", defaultNamespace); // Jeff Lanning ([email protected]): Added optional "alias" attribute for use in OPath queries (and to help code generators build entity classes) string alias = this.GetValue(attributeNode, "alias", member); // optional queryOnly is used to enable OPath on relationships without actually loading any relationships -- no member allowed, alias is required bool queryOnly; // Default queryOnly is False switch (this.GetValue(attributeNode, "queryOnly", "FALSE").ToUpper()) { case "TRUE": queryOnly = true; break; default: queryOnly = false; break; } if (!queryOnly) { if (member == null || member.Length == 0) { throw new MappingException("Mapping: Relation attribute 'member' must be specified when 'queryOnly' is set to false - " + entity.Type + " : " + member); } } else { if (member != null && member.Length > 0) { throw new MappingException("Mapping: Relation attribute 'member' is not allowed when 'queryOnly' is set to true - " + entity.Type + " : " + member); } if (alias == null || alias.Length == 0) { throw new MappingException("Mapping: Relation attribute 'alias' must be specified when queryOnly is set to true - " + entity.Type + " : " + type); } member = alias; // Required internally for hashtables, but would be inconsistent if allowed externally } bool lazyLoad; // Default lazyLoad is True switch (this.GetValue(attributeNode, "lazyLoad", "TRUE").ToUpper()) { case "FALSE": lazyLoad = false; break; default: lazyLoad = true; break; } // CascadeDelete help from Ken Muse (http://www.MomentsFromImpact.com) bool cascadeDelete; // Default cascaseDelete is False switch (this.GetValue(attributeNode, "cascadeDelete", "FALSE").ToUpper()) { case "TRUE": cascadeDelete = true; break; default: cascadeDelete = false; break; } string filter = this.GetValue(attributeNode, "filter"); string sortOrder = this.GetValue(attributeNode, "sortOrder"); string selectSP = this.GetValue(attributeNode, "selectSP"); if (relationship == Relationship.Child) { entity.AddChild(member, field, type, alias, queryOnly, lazyLoad, cascadeDelete, filter, sortOrder, selectSP, this.provider); } else if (relationship == Relationship.Parent) { entity.AddParent(member, field, type, alias, queryOnly, lazyLoad, cascadeDelete, filter, sortOrder, selectSP, this.provider); } else { string table = this.GetTableName(attributeNode, "table", defaultSchema); string source = this.GetValue(attributeNode, "sourceField"); string dest = this.GetValue(attributeNode, "destField"); string insertSP = this.GetValue(attributeNode, "insertSP"); string deleteSP = this.GetValue(attributeNode, "deleteSP"); entity.AddMany(member, field, type, alias, table, source, dest, queryOnly, lazyLoad, cascadeDelete, filter, sortOrder, selectSP, insertSP, deleteSP, this.provider); } }