Пример #1
0
        private static void PrepareSourceTree(Source currentSource, ref ClassDef currentClassDef)
        {
            while (currentSource != null)
            {
                Source childSource = currentSource.ChildSource;
                currentSource.EntityName = currentClassDef.GetTableName();
                if (childSource != null)
                {
                    string           relationshipName = childSource.Name;
                    IRelationshipDef relationshipDef  = currentClassDef.GetRelationship(relationshipName);
                    if (relationshipDef == null)
                    {
                        string message = string.Format("'{0}' does not have a relationship called '{1}'.",
                                                       currentClassDef.ClassName, relationshipName);
                        throw new RelationshipNotFoundException(message);
                    }
                    foreach (RelPropDef relPropDef in relationshipDef.RelKeyDef)
                    {
                        string ownerFieldName   = currentClassDef.GetPropDef(relPropDef.OwnerPropertyName).DatabaseFieldName;
                        string relatedFieldName =
                            relationshipDef.RelatedObjectClassDef.GetPropDef(relPropDef.RelatedClassPropName).DatabaseFieldName;
                        QueryField fromField = new QueryField(relPropDef.OwnerPropertyName, ownerFieldName, currentSource);
                        QueryField toField   = new QueryField(relPropDef.RelatedClassPropName, relatedFieldName, childSource);
                        currentSource.Joins[0].JoinFields.Add(new Source.Join.JoinField(fromField, toField));
                    }
                    currentClassDef = (ClassDef)relationshipDef.RelatedObjectClassDef;
                }

                currentSource = childSource;
            }
        }
Пример #2
0
        private static void PrepareSourceTree(Source currentSource, ref ClassDef currentClassDef)
        {
            while (currentSource != null)
            {
                Source childSource = currentSource.ChildSource;
                currentSource.EntityName = currentClassDef.GetTableName();
                if (childSource != null)
                {
                    string relationshipName = childSource.Name;
                    IRelationshipDef relationshipDef = currentClassDef.GetRelationship(relationshipName);
                    if (relationshipDef == null)
                    {
                        string message = string.Format("'{0}' does not have a relationship called '{1}'.",
                                                       currentClassDef.ClassName, relationshipName);
                        throw new RelationshipNotFoundException(message);
                    }
                    foreach (RelPropDef relPropDef in relationshipDef.RelKeyDef)
                    {
                        string ownerFieldName = currentClassDef.GetPropDef(relPropDef.OwnerPropertyName).DatabaseFieldName;
                        string relatedFieldName = 
                            relationshipDef.RelatedObjectClassDef.GetPropDef(relPropDef.RelatedClassPropName).DatabaseFieldName;
                        QueryField fromField = new QueryField(relPropDef.OwnerPropertyName, ownerFieldName, currentSource);
                        QueryField toField = new QueryField(relPropDef.RelatedClassPropName, relatedFieldName, childSource);
                        currentSource.Joins[0].JoinFields.Add(new Source.Join.JoinField(fromField, toField));
                    }
                    currentClassDef = (ClassDef) relationshipDef.RelatedObjectClassDef;
                }

                currentSource = childSource;
            }
        }