override public bool VisitCollection(QueryBuilderMappingParser.CollectionContext context) { if (Pass == 3) { MongoDBCollection collection = new MongoDBCollection(context.name.Text); List <MapRule> mapRules = new List <MapRule>(); if (context.erRefs() != null) { foreach (var er in context.erRefs().erRef()) { try { var erElement = EntityRelationshipModel.FindByName(er.refName.Text); var isMain = er.main == null ? false : true; MapRule mapRule = new MapRule(erElement, collection, isMain); mapRules.Add(mapRule); } catch (Exception) { Errors.Add($"Error 005: (line {er.refName.Line}:{er.refName.Column}): referenced ER element '{er.refName.Text}' not found!"); } } } foreach (var f in context.field()) { VisitField("", f, collection, mapRules); } MongoDBSchema.Collections.Add(collection); foreach (var mr in mapRules) { ERMongoMapping.Rules.Add(mr); } } return(true); }
override public bool VisitRelationship(QueryBuilderMappingParser.RelationshipContext context) { if (Pass == 2) { // RelationshipCardinality deveria fazer parte de RelationshipConnection Relationship relationship = new Relationship(context.name.Text); foreach (QueryBuilderMappingParser.AttributeContext ac in context.attribute()) { relationship.AddAttribute(ac.name.Text, ac.type.Text, ac.multivalued != null, ac.primarykey != null); } foreach (var end in context.relationshipEnd()) { RelationshipEnd rend = new RelationshipEnd(); try { var target = EntityRelationshipModel.FindByName(end.name.Text); if (target.GetType() != typeof(Entity)) { Errors.Add($"Error 003: (line {end.name.Line}:{end.name.Column}): relationship end '{end.name.Text}' is not an Entity!"); } else { rend.TargetEntity = (Entity)target; relationship.AddRelationshipEnd(rend); } } catch (Exception) { Errors.Add($"Error 004: (line {end.name.Line}:{end.name.Column}): relationship end '{end.name.Text}' not found!"); } } EntityRelationshipModel.Elements.Add(relationship); } return(true); }