public static bool IsAllowedEntityCollectionItem(CslaObjectInfo objectInfo) { if (objectInfo.IsEditableChild() || objectInfo.IsReadOnlyObject()) { return(true); } return(false); }
public static bool IsNotRootType(this CslaObjectInfo info) { if (info.IsEditableChild() || (info.IsReadOnlyObject() && info.ParentType != string.Empty)) { return(true); } return(false); }
public static bool IsAllowedEntityObject(CslaObjectInfo objectInfo) { if (objectInfo.IsEditableRoot() || objectInfo.IsDynamicEditableRoot() || objectInfo.IsEditableChild() || objectInfo.IsEditableSwitchable() || objectInfo.IsReadOnlyObject()) { return(true); } return(false); }
// TODO Same "IsChildType" name but different results!!! When fixing, check also templates. public static bool IsChildType(this CslaObjectInfo info) { if (info.IsEditableSwitchable() || info.IsEditableChild() || info.IsEditableChildCollection() || ((info.IsReadOnlyObject() || info.IsReadOnlyCollection()) && info.ParentType != string.Empty)) { return(true); } return(false); }
public static bool IsCompatibleEntityCollectionItemPair(CslaObjectInfo collectionObjectInfo, CslaObjectInfo itemObjectInfo) { if (collectionObjectInfo.IsEditableChildCollection() && itemObjectInfo.IsEditableChild()) { return(true); } if (collectionObjectInfo.IsReadOnlyCollection() && itemObjectInfo.IsReadOnlyObject()) { return(true); } return(false); }
public static bool IsRootType(this CslaObjectInfo info) { if (info.IsEditableRoot() || info.IsEditableRootCollection() || info.IsDynamicEditableRoot() || info.IsDynamicEditableRootCollection() || info.IsEditableSwitchable() || ((info.IsReadOnlyObject() || info.IsReadOnlyCollection()) && info.ParentType == string.Empty)) { return(true); } return(false); }
public static bool CanHaveParentProperties(this CslaObjectInfo info) { if (info.ObjectType.IsCollectionType()) { return(false); // Object is a collection and thus has no Properties } if (info.IsEditableRoot() || info.IsDynamicEditableRoot()) { return(false); // Object is root and thus has no ParentType } var parent = info.Parent.CslaObjects.Find(info.ParentType); if (parent == null) { return(info.IsReadOnlyObject()); } // Object is ReadOnly and might have ParentProperties if (parent.ObjectType.IsCollectionType()) // ParentType is a collection and thus has no Properties { if (parent.IsEditableRootCollection() || parent.IsDynamicEditableRootCollection() || (parent.IsReadOnlyCollection() && parent.ParentType == string.Empty)) { return(false); // ParentType is a root collection; end of line } return(true); // There should be a grand-parent with properties } if (parent.ObjectType.IsObjectType()) { return(true); // ParentType exists and has properties } return(false); }
private void BuildCollectionItemCriteriaDelete(CslaObjectInfo info, CslaObjectInfo myRootInfo, CslaObjectInfo otherRootInfo, bool isManyToMany) { const string critName = "CriteriaDelete"; // don't generate CriteriaNew for read-only objects if (info.IsReadOnlyObject()) { RemoveDefaultItemCriteria(info, critName); return; } StringBuilder sb; // make collection item criteria if needed var itemCriteria = info.CriteriaObjects; Criteria criteria = null; foreach (var crit in itemCriteria) { if (CheckCollectionItemCriteriaDelete(crit, info, myRootInfo, critName)) { criteria = crit; break; } } if (criteria == null) { criteria = new Criteria(info) { Name = critName }; SetCollectionItemCriteriaDelete(criteria, info, myRootInfo == MainObjectInfo, critName); info.CriteriaObjects.Add(criteria); // display message to the user sb = new StringBuilder(); sb.AppendFormat("Successfully added criteria {0} to {1} item object.", critName, info.ObjectName); OutputWindow.Current.AddOutputInfo(sb.ToString()); } if (criteria.Name != critName) { return; } if (criteria.Properties.Count > 0) { // clear CriteriaDelete properties criteria.Properties.Clear(); // display message to the user sb = new StringBuilder(); sb.AppendFormat("Successfully removed all criteria properties of {0} on {1} item object.", critName, info.ObjectName); OutputWindow.Current.AddOutputInfo(sb.ToString()); } // populate collection Criteria properties var addedProps = AddCriteriaProperties(info, criteria, myRootInfo, otherRootInfo, false, isManyToMany); if (addedProps.Count > 0) { // display message to the user sb = new StringBuilder(); sb.AppendFormat("Successfully added the following properties to criteria {0}:" + Environment.NewLine, criteria.Name); foreach (var propName in addedProps) { sb.AppendFormat("\t{0}.{1}.{2}" + Environment.NewLine, critName, info.ObjectName, propName); } OutputWindow.Current.AddOutputInfo(sb.ToString()); } }
public void BuildRelationObjects(AssociativeEntity.EntityFacade entity) { StringBuilder sb; var isManyToMany = (_entity.RelationType == ObjectRelationType.ManyToMany); // make property if needed ChildProperty child; if (FacadeObjectInfo.ChildCollectionProperties.Contains(entity.PropertyName)) { child = FacadeObjectInfo.ChildCollectionProperties.Find(entity.PropertyName); } else { child = new ChildProperty { Name = entity.PropertyName }; FacadeObjectInfo.ChildCollectionProperties.Add(child); // display message to the user sb = new StringBuilder(); sb.AppendFormat("Successfully added ChildProperty {0} to {1} object.", entity.PropertyName, FacadeObjectInfo.ObjectName); OutputWindow.Current.AddOutputInfo(sb.ToString()); } child.ParameterName = entity.PropertyName; child.TypeName = entity.CollectionTypeName; child.DeclarationMode = PropertyDeclaration.Managed; child.ReadOnly = FacadeObjectInfo.IsReadOnlyObject(); child.Nullable = false; child.LazyLoad = entity.LazyLoad; child.LoadingScheme = entity.LoadingScheme; // LoadParameters might be re-filled by BuildCollectionCriteriaGet child.LoadParameters = entity.LoadParameters; child.Access = PropertyAccess.IsPublic; child.Undoable = true; // make collection if needed var coll = _cslaObjects.Find(entity.CollectionTypeName); if (coll == null) { coll = new CslaObjectInfo(_currentUnit) { ObjectType = CslaObjectType.EditableChildCollection, ObjectName = entity.CollectionTypeName }; _currentUnit.CslaObjects.InsertAtTop(coll); // display message to the user sb = new StringBuilder(); sb.AppendFormat("Successfully added {0} collection object.", entity.CollectionTypeName); OutputWindow.Current.AddOutputInfo(sb.ToString()); } // populate collection coll.ParentType = entity.ObjectName; coll.ParentProperties = BuildParentProperties(coll); coll.ItemType = entity.ItemTypeName; // handle collection criteria BuildCollectionCriteriaGet(coll, entity, child); /* handle item */ var item = _cslaObjects.Find(entity.ItemTypeName); if (item == null) { item = new CslaObjectInfo(_currentUnit) { ObjectType = CslaObjectType.EditableChild, ObjectName = entity.ItemTypeName }; _currentUnit.CslaObjects.InsertAtTop(item); // display message to the user sb = new StringBuilder(); sb.AppendFormat("Successfully added {0} collection item object.", entity.ItemTypeName); OutputWindow.Current.AddOutputInfo(sb.ToString()); } // populate collection item if (!isManyToMany) { item.ParentInsertOnly = true; } else { item.ParentInsertOnly = false; } item.ParentType = entity.CollectionTypeName; item.ParentProperties = BuildParentProperties(item); var suffix = string.Empty; var objectName = entity.ItemTypeName; if (isManyToMany && !_entity.MainLazyLoad && !_entity.SecondaryLazyLoad && _entity.Parent.Params.ORBItemsUseSingleSP) { suffix = _entity.Parent.Params.ORBSingleSPSuffix; objectName = _entity.MainItemTypeName; } if (item.IsNotReadOnlyObject()) { if (item.GenerateDataPortalInsert) { item.InsertProcedureName = _entity.Parent.Params.GetAddProcName(objectName) + suffix; } if (item.GenerateDataPortalUpdate) { item.UpdateProcedureName = _entity.Parent.Params.GetUpdateProcName(objectName) + suffix; } } else { item.InsertProcedureName = string.Empty; item.UpdateProcedureName = string.Empty; } // prepare for deprecate item.DeleteProcedureName = string.Empty; // handle collection item CriteriaNew if (!isManyToMany) { BuildCollectionItemCriteriaNew(item, null, null, false); } else { if (FacadeObjectInfo == MainObjectInfo) { BuildCollectionItemCriteriaNew(item, null, SecondaryObjectInfo, true); } else { BuildCollectionItemCriteriaNew(item, null, MainObjectInfo, true); } } // handle collection item Criteria if (!isManyToMany) { BuildCollectionItemCriteriaDelete(item, null, null, false); } else { if (FacadeObjectInfo == MainObjectInfo) { BuildCollectionItemCriteriaDelete(item, MainObjectInfo, SecondaryObjectInfo, true); } else { BuildCollectionItemCriteriaDelete(item, SecondaryObjectInfo, MainObjectInfo, true); } } }
public void SetValuePropertyInfo(IDataBaseObject obj, IResultSet rs, IColumnInfo prop, ValueProperty destination) { var p = prop; SetDbBindColumn(obj, rs, p, destination.DbBindColumn); destination.Nullable = (p.IsNullable); if (p.NativeType == "timestamp") { destination.ReadOnly = true; destination.Undoable = false; destination.DeclarationMode = PropertyDeclaration.Managed; } if (_currentCslaObject.IsReadOnlyObject() || _currentCslaObject.IsNameValueList()) { destination.DeclarationMode = PropertyDeclaration.Managed; destination.ReadOnly = true; } if (p.IsPrimaryKey) { destination.Undoable = false; if (p.IsIdentity) { destination.PrimaryKey = ValueProperty.UserDefinedKeyBehaviour.DBProvidedPK; destination.ReadOnly = true; destination.PropSetAccessibility = AccessorVisibility.Default; } else { destination.PrimaryKey = ValueProperty.UserDefinedKeyBehaviour.UserProvidedPK; } if (destination.PropertyType == TypeCodeEx.Guid) { destination.DefaultValue = _currentUnit.Params.IDGuidDefaultValue; } else if (p.IsIdentity && _currentCslaObject.IsNotReadOnlyObject() && _currentCslaObject.IsNotNameValueList()) { switch (p.DbType) { case DbType.Int16: destination.DefaultValue = _currentUnit.Params.IDInt16DefaultValue; break; case DbType.Int32: destination.DefaultValue = _currentUnit.Params.IDInt32DefaultValue; break; case DbType.Int64: destination.DefaultValue = _currentUnit.Params.IDInt64DefaultValue; break; } } } if (_currentUnit.Params.CreationDateColumn == p.ColumnName) { destination.ReadOnly = true; destination.Undoable = false; destination.PropSetAccessibility = AccessorVisibility.Default; destination.DataAccess = ValueProperty.DataAccessBehaviour.CreateOnly; if (destination.PropertyType == TypeCodeEx.SmartDate) { destination.DefaultValue = _currentUnit.Params.LogDateAndTime ? "new SmartDate(" + GetNowValue(TypeCodeEx.DateTime) + ")" : "new SmartDate(DateTime.Today)"; } else { destination.DefaultValue = _currentUnit.Params.LogDateAndTime ? GetNowValue(destination.PropertyType) : "DateTime.Today"; } } else if (_currentUnit.Params.CreationUserColumn == p.ColumnName) { destination.ReadOnly = true; destination.Undoable = false; destination.PropSetAccessibility = AccessorVisibility.Default; destination.DataAccess = ValueProperty.DataAccessBehaviour.CreateOnly; destination.DefaultValue = _currentUnit.Params.GetUserMethod; } else if (_currentUnit.Params.ChangedDateColumn == p.ColumnName) { destination.ReadOnly = true; destination.Undoable = false; destination.PropSetAccessibility = AccessorVisibility.Default; if (_currentCslaObject.IsCreationDateColumnPresent()) { destination.DefaultValue = "$" + _currentUnit.Params.CreationDateColumn; } else { if (destination.PropertyType == TypeCodeEx.SmartDate) { destination.DefaultValue = _currentUnit.Params.LogDateAndTime ? "new SmartDate(" + GetNowValue(TypeCodeEx.DateTime) + ")" : "new SmartDate(DateTime.Today)"; } else { destination.DefaultValue = _currentUnit.Params.LogDateAndTime ? GetNowValue(destination.PropertyType) : "DateTime.Today"; } } } else if (_currentUnit.Params.ChangedUserColumn == p.ColumnName) { destination.ReadOnly = true; destination.Undoable = false; destination.PropSetAccessibility = AccessorVisibility.Default; if (_currentCslaObject.IsCreationUserColumnPresent()) { destination.DefaultValue = "$" + _currentUnit.Params.CreationUserColumn; } else { destination.DefaultValue = _currentUnit.Params.GetUserMethod; } } else if (_currentUnit.Params.DatesDefaultStringWithTypeConversion && (destination.PropertyType == TypeCodeEx.SmartDate || destination.PropertyType == TypeCodeEx.DateTime || destination.PropertyType == TypeCodeEx.DateTimeOffset)) { destination.BackingFieldType = destination.PropertyType; destination.PropertyType = TypeCodeEx.String; destination.DeclarationMode = PropertyDeclaration.ManagedWithTypeConversion; } }
public static bool IsNotReadOnlyObject(this CslaObjectInfo info) { return(!info.IsReadOnlyObject()); }