public void Add(CslaObjectInfo mainObject) { if (RelationRulesEngine.IsAllowedEntityObject(mainObject)) { var entity = new AssociativeEntity(GeneratorController.Current.CurrentUnit); entity.RelationType = ObjectRelationType.OneToMultiple; entity.ObjectName = mainObject.ObjectName; entity.MainObject = mainObject.ObjectName; entity.MainLazyLoad = false; entity.SecondaryLazyLoad = false; var mainCriteriaInfo = typeof(CslaObjectInfo).GetProperty("CriteriaObjects"); var mainCriteriaObjects = mainCriteriaInfo.GetValue(mainObject, null); foreach (var crit in (CriteriaCollection)mainCriteriaObjects) { foreach (var prop in crit.Properties) { entity.MainLoadProperties.Add(CriteriaProperty.Clone(prop)); } } Add(entity); } else { throw new Exception(mainObject + " isn't a suitable object for this builder."); } }
public void Add(CslaObjectInfo mainObject, CslaObjectInfo secondaryObject) { if (RelationRulesEngine.IsAllowedEntityObject(mainObject)) { if (RelationRulesEngine.IsAllowedEntityObject(secondaryObject)) { var entity = new AssociativeEntity(GeneratorController.Current.CurrentUnit); entity.RelationType = ObjectRelationType.ManyToMany; entity.ObjectName = mainObject.ObjectName + secondaryObject.ObjectName; entity.MainLazyLoad = false; entity.SecondaryLazyLoad = false; entity.MainObject = mainObject.ObjectName; entity.MainPropertyName = secondaryObject.ObjectName + entity.Parent.Params.ORBChildPropertySuffix; entity.MainItemTypeName = mainObject.ObjectName + secondaryObject.ObjectName; entity.MainCollectionTypeName = entity.MainItemTypeName + entity.Parent.Params.ORBCollectionSuffix; var mainCriteriaInfo = typeof(CslaObjectInfo).GetProperty("CriteriaObjects"); var mainCriteriaObjects = mainCriteriaInfo.GetValue(mainObject, null); foreach (var crit in (CriteriaCollection)mainCriteriaObjects) { foreach (var prop in crit.Properties) { entity.MainLoadProperties.Add(CriteriaProperty.Clone(prop)); } } entity.SecondaryObject = secondaryObject.ObjectName; entity.SecondaryPropertyName = mainObject.ObjectName + entity.Parent.Params.ORBChildPropertySuffix; entity.SecondaryItemTypeName = secondaryObject.ObjectName + mainObject.ObjectName; entity.SecondaryCollectionTypeName = entity.SecondaryItemTypeName + entity.Parent.Params.ORBCollectionSuffix; var secondaryCriteriaInfo = typeof(CslaObjectInfo).GetProperty("CriteriaObjects"); var secondaryCriteriaObjects = secondaryCriteriaInfo.GetValue(secondaryObject, null); foreach (var crit in (CriteriaCollection)secondaryCriteriaObjects) { foreach (var prop in crit.Properties) { entity.SecondaryLoadProperties.Add(CriteriaProperty.Clone(prop)); } } Add(entity); } else { throw new Exception(secondaryObject + " isn't a suitable object for this builder."); } } else { throw new Exception(mainObject + " isn't a suitable object for this builder."); } }
public List <string> GetAllParentNames(CslaObjectType cslaType) { var lst = new List <string>(); foreach (var obj in this) { if (RelationRulesEngine.IsParentAllowed(obj.ObjectType, cslaType)) { lst.Add(obj.ObjectName); } } return(lst); }
public List <string> GetAllChildNames(CslaObjectType cslaType) { var list = new List <string>(); foreach (CslaObjectInfo obj in this) { if (RelationRulesEngine.IsChildAllowed(obj.ObjectType, cslaType)) { list.Add(obj.ObjectName); } } return(list); }
public List <string> GetAllParentNames(CslaObjectInfo info) { var lst = new List <string>(); foreach (CslaObjectInfo obj in this) { if (RelationRulesEngine.IsParentAllowed(obj.ObjectType, info.ObjectType) && obj != info) { lst.Add(obj.ObjectName); } } return(lst); }
private void ValidManyToMany() { ValidOneToMany(); var secondaryCslaObject = _cslaObjects.Find(SecondaryObject); var secondaryCslaObjectCollection = _cslaObjects.Find(SecondaryCollectionTypeName); var secondaryCslaObjectItem = _cslaObjects.Find(SecondaryItemTypeName); if (secondaryCslaObject == null) { _validationError += "Secondary Object not found." + Environment.NewLine; } else if (!RelationRulesEngine.IsAllowedEntityObject(secondaryCslaObject)) { _validationError += SecondaryObject + " isn't allowed to be Secondary Object." + Environment.NewLine; } if (secondaryCslaObjectCollection == null) { if (string.IsNullOrEmpty(SecondaryCollectionTypeName)) { _validationError += "Secondary Collection must be filled." + Environment.NewLine; } } else if (!RelationRulesEngine.IsAllowedEntityCollection(secondaryCslaObjectCollection)) { _validationError += SecondaryCollectionTypeName + " isn't allowed to be Secondary Collection." + Environment.NewLine; } else { _validationError += ValidateLoadingScheme(SecondaryLoadingScheme, SecondaryLazyLoad, "Secondary"); } if (secondaryCslaObjectItem == null) { if (string.IsNullOrEmpty(SecondaryItemTypeName)) { _validationError += "Secondary Collection Item must be filled." + Environment.NewLine; } } else if (!RelationRulesEngine.IsAllowedEntityCollectionItem(secondaryCslaObjectItem)) { _validationError += SecondaryItemTypeName + " isn't allowed to be Secondary Collection Item." + Environment.NewLine; } if (secondaryCslaObjectCollection != null && secondaryCslaObjectItem != null) { if ( !RelationRulesEngine.IsCompatibleEntityCollectionItemPair(secondaryCslaObjectCollection, secondaryCslaObjectItem)) { _validationError += SecondaryCollectionTypeName + " Collection is not compatible with " + SecondaryItemTypeName + " Collection Item." + Environment.NewLine; } if (!IsChildCorrect(_cslaObjects, SecondaryObject, SecondaryCollectionTypeName)) { _validationError += SecondaryObject + " must be the parent of " + SecondaryCollectionTypeName + "." + Environment.NewLine; } if (!IsChildCorrect(_cslaObjects, SecondaryCollectionTypeName, SecondaryItemTypeName)) { _validationError += SecondaryCollectionTypeName + " must be the parent of " + SecondaryItemTypeName + "." + Environment.NewLine; } if (!IsItemCorrect(_cslaObjects, SecondaryCollectionTypeName, SecondaryItemTypeName)) { _validationError += SecondaryCollectionTypeName + " item must be " + SecondaryItemTypeName + "." + Environment.NewLine; } } var mainCslaObject = _cslaObjects.Find(MainObject); if (ObjectRelationsFactory.FindAssociativeTable(mainCslaObject, secondaryCslaObject) == null) { _validationError += "Associative table not found."; } }
private void ValidOneToMany() { var mainCslaObject = _cslaObjects.Find(MainObject); var mainCslaObjectCollection = _cslaObjects.Find(MainCollectionTypeName); var mainCslaObjectItem = _cslaObjects.Find(MainItemTypeName); if (mainCslaObject == null) { _validationError += "Primary Object not found." + Environment.NewLine; } else if (!RelationRulesEngine.IsAllowedEntityObject(mainCslaObject)) { _validationError += MainObject + " isn't allowed to be Primary Object." + Environment.NewLine; } else { _validationError += ValidateLoadingScheme(MainLoadingScheme, MainLazyLoad, "Primary"); } if (mainCslaObjectCollection == null) { if (string.IsNullOrEmpty(MainCollectionTypeName)) { _validationError += "Primary Collection must be filled." + Environment.NewLine; } else { if (RelationType == ObjectRelationType.OneToMany) { _validationError += "Primary Collection not found." + Environment.NewLine; } } } else if (!RelationRulesEngine.IsAllowedEntityCollection(mainCslaObjectCollection)) { _validationError += MainCollectionTypeName + " isn't allowed to be Primary Collection." + Environment.NewLine; } if (mainCslaObjectItem == null) { if (string.IsNullOrEmpty(MainItemTypeName)) { _validationError += "Primary Collection Item must be filled." + Environment.NewLine; } else { if (RelationType == ObjectRelationType.OneToMany) { _validationError += "Primary Collection Item not found." + Environment.NewLine; } } } else if (!RelationRulesEngine.IsAllowedEntityCollectionItem(mainCslaObjectItem)) { _validationError += MainItemTypeName + " isn't allowed to be Primary Collection Item." + Environment.NewLine; } if (mainCslaObjectCollection != null && mainCslaObjectItem != null) { if (!RelationRulesEngine.IsCompatibleEntityCollectionItemPair(mainCslaObjectCollection, mainCslaObjectItem)) { _validationError += MainCollectionTypeName + " Collection is not compatible with " + MainItemTypeName + " Collection Item." + Environment.NewLine; } if (!IsChildCorrect(_cslaObjects, MainObject, MainCollectionTypeName)) { _validationError += MainObject + " must be the parent of " + MainCollectionTypeName + "." + Environment.NewLine; } if (!IsChildCorrect(_cslaObjects, MainCollectionTypeName, MainItemTypeName)) { _validationError += MainCollectionTypeName + " must be the parent of " + MainItemTypeName + "." + Environment.NewLine; } if (!IsItemCorrect(_cslaObjects, MainCollectionTypeName, MainItemTypeName)) { _validationError += MainCollectionTypeName + " item must be " + MainItemTypeName + "." + Environment.NewLine; } } }