public static bool IsAllowedEntityObject(CslaObjectInfo objectInfo) { if (objectInfo.IsEditableRoot() || objectInfo.IsDynamicEditableRoot() || objectInfo.IsEditableChild() || objectInfo.IsEditableSwitchable() || objectInfo.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); }
/// <summary> /// Should be called after the object has all it's properties (if applicable). /// It creates the default criteria classes depending on the object type. /// </summary> /// <param name="getSprocName">Name of the sproc.</param> internal void AddDefaultCriteriaAndParameters(string getSprocName) { if (_currentCslaObject.CriteriaObjects.Count != 0) { return; } if (_currentCslaObject.IsEditableRootCollection() || _currentCslaObject.IsDynamicEditableRootCollection()) { if (_currentUnit.Params.AutoCriteria) { var crit = CreateEmptyNewAndFetchCriteria(); _currentCslaObject.CriteriaObjects.Add(crit); crit.SetSprocNames(); } //no need to go through the properties here. return; } if (_currentCslaObject.IsNameValueList() || (_currentCslaObject.IsReadOnlyCollection() && _currentCslaObject.ParentType == string.Empty)) { if (_currentUnit.Params.AutoCriteria) { var crit = CreateEmptyFetchCriteria(); _currentCslaObject.CriteriaObjects.Add(crit); crit.SetSprocNames(getSprocName); } //no need to go through the properties here. return; } // Condition excludes NameValueList if (_currentCslaObject.ObjectType.IsCollectionType()) { return; } var primaryKeyProperties = new List <ValueProperty>(); ValueProperty timestampProperty = null; var useForCreate = false; // retrieve all primary key and timestamp properties foreach (var prop in _currentCslaObject.ValueProperties) { if (prop.PrimaryKey != ValueProperty.UserDefinedKeyBehaviour.Default) { primaryKeyProperties.Add(prop); if (!(prop.DbBindColumn.IsIdentity || prop.PropertyType == TypeCodeEx.Guid)) { useForCreate = true; } } else if (prop.DbBindColumn.NativeType == "timestamp") { timestampProperty = prop; } } if (primaryKeyProperties.Count > 0 || timestampProperty != null) { // Try to find default Criteria object Criteria defaultCriteria = _currentCslaObject.CriteriaObjects.Find("Criteria"); Criteria timestampCriteria = _currentCslaObject.CriteriaObjects.Find("CriteriaTS"); // If criteria objects are not set if (_currentCslaObject.CriteriaObjects.Count == 0) { // If default criteria doesn't exists, create a new criteria if (defaultCriteria == null) { if (!(_currentCslaObject.IsReadOnlyObject() && _currentCslaObject.ParentType != string.Empty)) { defaultCriteria = new Criteria(_currentCslaObject); defaultCriteria.Name = _currentCslaObject.IsReadOnlyObject() ? "CriteriaGet" : "Criteria"; defaultCriteria.GetOptions.Enable(); if (_currentCslaObject.IsEditableRoot() || _currentCslaObject.IsEditableSwitchable() || _currentCslaObject.IsEditableChild() || _currentCslaObject.IsDynamicEditableRoot()) { defaultCriteria.DeleteOptions.Enable(); if (defaultCriteria.Properties.Count > 0 && useForCreate) { defaultCriteria.CreateOptions.Factory = true; defaultCriteria.CreateOptions.DataPortal = true; defaultCriteria.CreateOptions.RunLocal = true; } else { var createCriteria = _currentCslaObject.CriteriaObjects.Find("CriteriaNew"); if (createCriteria == null) { createCriteria = new Criteria(_currentCslaObject); createCriteria.Name = "CriteriaNew"; createCriteria.CreateOptions.DataPortal = true; createCriteria.CreateOptions.Factory = true; createCriteria.CreateOptions.RunLocal = true; _currentCslaObject.CriteriaObjects.Add(createCriteria); } } } if (_currentCslaObject.IsEditableChild()) { return; } defaultCriteria.SetSprocNames(); if (_currentCslaObject.IsDynamicEditableRoot()) { defaultCriteria.Name = "CriteriaDelete"; defaultCriteria.GetOptions.Factory = false; defaultCriteria.GetOptions.DataPortal = false; defaultCriteria.GetOptions.Procedure = false; defaultCriteria.GetOptions.ProcedureName = string.Empty; } else if (_currentCslaObject.IsNotEditableRoot() && _currentCslaObject.IsNotEditableSwitchable() && _currentCslaObject.IsNotReadOnlyObject()) { defaultCriteria.Name = "CriteriaDelete"; defaultCriteria.GetOptions.Factory = false; defaultCriteria.GetOptions.DataPortal = false; defaultCriteria.GetOptions.Procedure = false; defaultCriteria.GetOptions.ProcedureName = string.Empty; defaultCriteria.DeleteOptions.Factory = false; defaultCriteria.DeleteOptions.DataPortal = false; } _currentCslaObject.CriteriaObjects.Add(defaultCriteria); AddPropertiesToCriteria(primaryKeyProperties, defaultCriteria); if (_currentUnit.Params.AutoTimestampCriteria && timestampProperty != null && timestampCriteria == null) { AddTimestampProperty(defaultCriteria, timestampProperty); } } } } } else if (getSprocName != string.Empty && _currentUnit.Params.AutoCriteria) { var crit = CreateEmptyFetchCriteria(); _currentCslaObject.CriteriaObjects.Add(crit); crit.SetSprocNames(getSprocName); } }
public static bool IsNotDynamicEditableRoot(this CslaObjectInfo info) { return(!info.IsDynamicEditableRoot()); }