Beispiel #1
0
        private string InternalCreateSqlFromDefinitions(ModelDefinition sourceDef, ModelDefinition targetDef, bool isCrossJoin)
        {
            var parentDef = sourceDef;
            var childDef  = targetDef;

            var refField = parentDef.GetRefFieldDefIfExists(childDef);

            if (refField == null)
            {
                parentDef = targetDef;
                childDef  = sourceDef;
                refField  = parentDef.GetRefFieldDefIfExists(childDef);
            }

            if (refField == null)
            {
                if (!isCrossJoin)
                {
                    throw new ArgumentException("Could not infer relationship between {0} and {1}".Fmt(sourceDef.ModelName, targetDef.ModelName));
                }

                return(string.Empty);
            }

            return("{0}\n({1}.{2} = {3}.{4})".Fmt(
                       isCrossJoin ? "WHERE" : "ON",
                       DialectProvider.GetQuotedTableName(parentDef),
                       SqlColumn(parentDef.PrimaryKey.FieldName),
                       DialectProvider.GetQuotedTableName(childDef),
                       SqlColumn(refField.FieldName)));
        }