public void StoreCorrelationNames(CslaObjectInfo info) { correlationNames.Clear(); DuplicateTables readCorr; DuplicateTables writeCorr = new DuplicateTables(); ValuePropertyCollection vpc = new ValuePropertyCollection(); vpc.AddRange(info.GetAllValueProperties()); for (int vp = 0; vp < vpc.Count; vp++) { int count = 1; for (int prop = 0; prop < vp; prop++) { readCorr = correlationNames[prop]; if (readCorr.PropertyName != vpc[vp].Name) { if (readCorr.TableName == vpc[vp].DbBindColumn.ObjectName && readCorr.ColumnName == vpc[vp].DbBindColumn.ColumnName) { if (readCorr.Order >= count) { count = readCorr.Order + 1; } } } } writeCorr.PropertyName = vpc[vp].Name; writeCorr.TableName = vpc[vp].DbBindColumn.ObjectName; writeCorr.ColumnName = vpc[vp].DbBindColumn.ColumnName; writeCorr.Order = count; correlationNames.Add(writeCorr); } }
public string GetFromClause(Criteria crit, CslaObjectInfo info, bool includeParentObjects) { // check object uses FKConstraint field bool FKField = false; ValuePropertyCollection valPropColl = new ValuePropertyCollection(); valPropColl.AddRange(info.GetAllValueProperties()); foreach (ValueProperty valProp in valPropColl) { if (valProp.FKConstraint != string.Empty) { FKField = true; break; } } if (FKField) { return(GetFromClauseFK(crit, info, includeParentObjects)); } else { return(GetFromClauseClassic(crit, info, includeParentObjects)); } }
public string GetSelectFields(CslaObjectInfo info) { StringBuilder sb = new StringBuilder(); sb.Append(Indent(2) + "SELECT" + Environment.NewLine); bool first = true; ValuePropertyCollection vpc = new ValuePropertyCollection(); if (IncludeParentProperties) { vpc.AddRange(info.GetParentValueProperties()); } vpc.AddRange(info.GetAllValueProperties()); foreach (ValueProperty prop in vpc) { if (prop.DataAccess != ValueProperty.DataAccessBehaviour.WriteOnly) { if (!first) { sb.Append("," + Environment.NewLine); } else { first = false; } sb.Append(Indent(3) + " "); if (prop.DbBindColumn.DataType.ToString() == "StringFixedLength") { sb.Append("RTRIM("); sb.Append("[" + GetCorrelationName(prop) + "].[" + prop.DbBindColumn.ColumnName + "]" + ")"); sb.Append(String.Format(" AS [{0}]", prop.ParameterName)); } else { sb.Append("[" + GetCorrelationName(prop) + "].[" + prop.DbBindColumn.ColumnName + "]"); if (prop.DbBindColumn.ColumnName != prop.ParameterName) { sb.Append(String.Format(" AS [{0}]", prop.ParameterName)); } } } } sb.Append(Environment.NewLine); return(sb.ToString()); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (provider != null) { editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (editorService != null) { if (context.Instance != null) { // CR modifying to accomodate PropertyBag Type instanceType = null; object objinfo = null; TypeHelper.GetContextInstanceObject(context, ref objinfo, ref instanceType); instance = objinfo.GetType(); PropertyInfo valuePropsInfo = instance.GetProperty("ValueProperties"); ValuePropertyCollection valueProps = (ValuePropertyCollection)valuePropsInfo.GetValue(objinfo, null); if (valueProps.Count > 0) { lstProperties.Items.Clear(); lstProperties.Items.Add(new DictionaryEntry("None", new ValueProperty())); for (int i = 0; i < valueProps.Count; i++) { lstProperties.Items.Add(new DictionaryEntry(valueProps[i].Name, valueProps[i])); } editorService.DropDownControl(lstProperties); if (lstProperties.SelectedItem != null) { ValueProperty prop = (ValueProperty)((DictionaryEntry)lstProperties.SelectedItem).Value; if (prop != null) { return(prop.Clone()); } } } } } } return(value); }
public string GetFromClauseFK(Criteria crit, CslaObjectInfo info, bool includeParentObjects) { List <IResultObject> tables = GetTables(crit, info, includeParentObjects); SortTables(tables); CheckTableJoins(tables); IResultObject curTable = tables[0]; StringBuilder sb = new StringBuilder(); sb.Append(Indent(2) + "FROM "); if (tables.Count == 1) { sb.AppendFormat("[{0}].[{1}]", tables[0].ObjectSchema, curTable.ObjectName); sb.Append(Environment.NewLine); return(sb.ToString()); } else if (tables.Count > 1) { sb.AppendFormat("[{0}].[{1}]", curTable.ObjectSchema, curTable.ObjectName); ValuePropertyCollection vpc = new ValuePropertyCollection(); vpc.AddRange(info.GetAllValueProperties()); foreach (ValueProperty vp in vpc) { if (vp.DbBindColumn.ObjectName != curTable.ObjectName) { List <IForeignKeyConstraint> fKeys = Catalog.ForeignKeyConstraints.GetConstraintsFor(curTable); foreach (IForeignKeyConstraint fKey in fKeys) { if (fKey.ConstraintName == vp.FKConstraint) { sb.Append(Environment.NewLine + Indent(3)); sb.Append(" INNER JOIN "); sb.AppendFormat("[{0}].[{1}]", curTable.ObjectSchema, fKey.PKTable.ObjectName); string corrName = GetCorrelationName(vp); if (corrName != vp.DbBindColumn.ObjectName) { sb.AppendFormat(" AS [{0}]", corrName); } sb.Append(" ON "); bool firstCol = true; for (int i = 0; i < fKey.Columns.Count; i++) { if (!firstCol) { sb.Append(" AND "); } else { firstCol = false; } sb.AppendFormat("[{0}].[{1}]", corrName, fKey.Columns[i].PKColumn.ColumnName); sb.Append(" = "); sb.Append(GetAliasedFieldString(fKey.ConstraintTable, fKey.Columns[i].FKColumn)); } break; } } } } sb.Append(Environment.NewLine); return(sb.ToString()); } else { return(String.Empty); } }