private bool inUse(DataAttribute dataAttribute) { if (dataAttribute.UsagesAsVariable.Count() > 0 || dataAttribute.UsagesAsParameter.Count() > 0) return true; else return false; }
public bool attributeInUse(DataAttribute attribute) { if (attribute.UsagesAsVariable.Count() == 0 && attribute.UsagesAsParameter.Count() == 0) return false; else return true; }
public static MessageModel validateAttributeDelete(long Id, DataAttribute dataAttribute) { if (dataAttribute != null && dataAttribute.Id != 0) { if (dataAttribute.UsagesAsVariable.Count == 0) { return new MessageModel() { hasMessage = false, Message = "Are you sure you want to delete the Variable Temlate " + dataAttribute.Name + " (" + dataAttribute.Id + ").", CssId = dataAttribute.Id.ToString() }; } else { try { return new MessageModel() { hasMessage = true, Message = "Can't delete the Variable Temlate " + dataAttribute.Name + " (" + dataAttribute.Id + ").", CssId = dataAttribute.Id.ToString() }; } catch { return new MessageModel() { hasMessage = true, Message = "Something is wrong with Variable Temlate " + Id, CssId = "0" }; } } } else { return new MessageModel() { hasMessage = true, Message = "Something is wrong with Variable Temlate " + Id, CssId = "0" }; } }
private string getFormalDescriptions(DataAttribute dataAttribute) { string FormalDescriptions = ""; BExIS.Dlm.Entities.DataStructure.Constraint temp = null; if (dataAttribute.Constraints != null && dataAttribute.Constraints.Count() > 0) { foreach (BExIS.Dlm.Entities.DataStructure.Constraint c in dataAttribute.Constraints) { temp = c; temp.Materialize(); if (FormalDescriptions == "") FormalDescriptions = temp.FormalDescription; else FormalDescriptions = FormalDescriptions + "\r\n" + temp.FormalDescription; } } return FormalDescriptions; }
public DataAttribute deletConstraint(long constraintId, DataAttribute attribute) { DataContainerManager dam = new DataContainerManager(); if (constraintId != 0 && attribute.Id != 0) { foreach (Constraint c in attribute.Constraints.ToList()) { if (c.Id == constraintId) { attribute.Constraints.Remove(c); if (c is RangeConstraint) dam.RemoveConstraint((RangeConstraint)c); if (c is PatternConstraint) dam.RemoveConstraint((PatternConstraint)c); if (c is DomainConstraint) dam.RemoveConstraint((DomainConstraint)c); break; } } } return (attribute); }
public bool DeleteDataAttribute(DataAttribute entity) { Contract.Requires(entity != null); Contract.Requires(entity.Id >= 0); using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository<DataAttribute> repo = uow.GetRepository<DataAttribute>(); IRepository<ExtendedProperty> exRepo = uow.GetRepository<ExtendedProperty>(); IRepository<Parameter> vpuRepo = uow.GetRepository<Parameter>(); entity = repo.Reload(entity); repo.LoadIfNot(entity.ExtendedProperties); //repo.LoadIfNot(entity.ParameterUsages); exRepo.Delete(entity.ExtendedProperties); entity.ExtendedProperties.Clear(); //vpuRepo.Delete(entity.ParameterUsages); //entity.ParameterUsages.Clear(); repo.Delete(entity); uow.Commit(); } // if any problem was detected during the commit, an exception will be thrown! return (true); }
private DataAttribute storeConstraint(ConstraintModel constraintModel, DataAttribute dataAttribute) { DataContainerManager dcManager = new DataContainerManager(); if (constraintModel is RangeConstraintModel) { RangeConstraintModel rcm = (RangeConstraintModel)constraintModel; if (rcm.Id == 0) { RangeConstraint constraint = new RangeConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, rcm.Description, rcm.Negated, null, null, null, rcm.Min, rcm.MinInclude, rcm.Max, rcm.MaxInclude); dcManager.AddConstraint(constraint, dataAttribute); } else { for(int i = 0; i < dataAttribute.Constraints.Count; i++) { if (dataAttribute.Constraints.ElementAt(i).Id == rcm.Id) { ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Description = rcm.Description; ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Negated = rcm.Negated; ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Lowerbound = rcm.Min; ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).LowerboundIncluded = rcm.MinInclude; ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Upperbound = rcm.Max; ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).UpperboundIncluded = rcm.MaxInclude; break; } } } } if (constraintModel is PatternConstraintModel) { PatternConstraintModel pcm = (PatternConstraintModel)constraintModel; if (pcm.Id == 0) { PatternConstraint constraint = new PatternConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, pcm.Description, pcm.Negated, null, null, null, pcm.MatchingPhrase, false); dcManager.AddConstraint(constraint, dataAttribute); } else { for (int i = 0; i < dataAttribute.Constraints.Count; i++) { if (dataAttribute.Constraints.ElementAt(i).Id == pcm.Id) { ((PatternConstraint)dataAttribute.Constraints.ElementAt(i)).Description = pcm.Description; ((PatternConstraint)dataAttribute.Constraints.ElementAt(i)).Negated = pcm.Negated; ((PatternConstraint)dataAttribute.Constraints.ElementAt(i)).MatchingPhrase = pcm.MatchingPhrase; break; } } } } if (constraintModel is DomainConstraintModel) { DomainConstraintModel dcm = (DomainConstraintModel)constraintModel; List<DomainItem> items = createDomainItems(dcm.Terms); dcm.Terms = cutSpaces(dcm.Terms); if (items.Count > 0) { if (dcm.Id == 0) { DomainConstraint constraint = new DomainConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, dcm.Description, dcm.Negated, null, null, null, items); dcManager.AddConstraint(constraint, dataAttribute); } else { DomainConstraint temp = new DomainConstraint(); for (int i = 0; i < dataAttribute.Constraints.Count; i++) { if (dataAttribute.Constraints.ElementAt(i).Id == dcm.Id) { temp = (DomainConstraint)dataAttribute.Constraints.ElementAt(i); temp.Materialize(); temp.Description = dcm.Description; temp.Negated = dcm.Negated; temp.Items = items; dcManager.AddConstraint(temp, dataAttribute); break; } } } } } return dataAttribute; }
public ActionResult editAttribute(DataAttributeModel Model) { ViewBag.Title = PresentationModel.GetViewTitleForTenant( "Manage Data Attributes", this.Session.GetTenant()); DataContainerManager dataAttributeManager = new DataContainerManager(); IList<DataAttribute> DataAttributeList = dataAttributeManager.DataAttributeRepo.Get(); long tempUnitId = Convert.ToInt64(Model.Unit.Id); long tempDataTypeId = Convert.ToInt64(Model.DataType.Id); Model.Id = Model.Id; Model.ShortName = cutSpaces(Model.ShortName); Model.Name = cutSpaces(Model.Name); Model.Description = cutSpaces(Model.Description); //if (Model.DomainConstraints.Count > 0) //{ // if (Model.DomainConstraints. != null && Model.DomainItems.Count > 0) // { // Model.DomainConstraints.FirstOrDefault().DomainItems = clearEmptyItems(Model.DomainItems); // } //} if (Model.Name == "" | Model.Name == null) { Session["nameMsg"] = "invalid Name"; Session["Window"] = true; return View("AttributeManager", new DataAttributeManagerModel(Model)); } else { bool nameNotExist = DataAttributeList.Where(p => p.Name.ToLower().Equals(Model.Name.ToLower())).Count().Equals(0); if (Model.Id == 0) { if (nameNotExist) { UnitManager UM = new UnitManager(); Unit unit = new Unit(); DataTypeManager DTM = new DataTypeManager(); DataType dataType = new DataType(); DataContainerManager DAM = new DataContainerManager(); DataAttribute temp = new DataAttribute(); if(UM.Repo.Get(tempUnitId)!= null) unit = UM.Repo.Get(tempUnitId); else unit = UM.Repo.Get().Where(u => u.Name.ToLower() == "none").FirstOrDefault(); if (DTM.Repo.Get(tempDataTypeId) != null) dataType = DTM.Repo.Get(tempDataTypeId); else dataType = DTM.Repo.Get().ToList().FirstOrDefault(); temp = DAM.CreateDataAttribute(Model.ShortName, Model.Name, Model.Description, false, false, "", MeasurementScale.Categorial, DataContainerType.ReferenceType, "", dataType, unit, null, null, null, null, null, null); #region store constraint if (Model.RangeConstraints.Count > 0 && (Model.RangeConstraints.FirstOrDefault().Min !=null || Model.RangeConstraints.FirstOrDefault().Max !=null) && (Model.RangeConstraints.FirstOrDefault().Min != 0.0 || Model.RangeConstraints.FirstOrDefault().Max != 0.0 )) temp = storeConstraint(Model.RangeConstraints.First(), temp); if (Model.PatternConstraints.Count > 0 && !String.IsNullOrEmpty(Model.PatternConstraints.FirstOrDefault().MatchingPhrase)) temp = storeConstraint(Model.PatternConstraints.First(), temp); if (Model.DomainConstraints.Count > 0) { foreach (DomainConstraintModel d in Model.DomainConstraints) { temp = storeConstraint(d, temp); } } #endregion temp = DAM.UpdateDataAttribute(temp); } else { Session["nameMsg"] = "Name already exist"; Session["Window"] = true; return View("AttributeManager", new DataAttributeManagerModel(Model)); } } else { if (nameNotExist || DataAttributeList.Where(p => p.Name.Equals(Model.Name)).ToList().First().Id == Model.Id) { DataAttribute dataAttribute = DataAttributeList.Where(p => p.Id.Equals(Model.Id)).ToList().First(); if (!attributeInUse(dataAttribute)) { DataContainerManager DAM = new DataContainerManager(); dataAttribute.Name = cutSpaces(Model.Name); dataAttribute.ShortName = Model.ShortName; dataAttribute.Description = Model.Description; UnitManager UM = new UnitManager(); if (UM.Repo.Get(tempUnitId) != null) dataAttribute.Unit = UM.Repo.Get(tempUnitId); else dataAttribute.Unit = UM.Repo.Get().Where(u => u.Name.ToLower() == "none").FirstOrDefault(); DataTypeManager DTM = new DataTypeManager(); if (DTM.Repo.Get(tempDataTypeId) != null) dataAttribute.DataType = DTM.Repo.Get(tempDataTypeId); else dataAttribute.DataType = DTM.Repo.Get().ToList().FirstOrDefault(); #region store constraint if (Model.RangeConstraints.Count > 0 && (Model.RangeConstraints.FirstOrDefault().Min != null || Model.RangeConstraints.FirstOrDefault().Max != null) && (Model.RangeConstraints.FirstOrDefault().Min != 0.0 || Model.RangeConstraints.FirstOrDefault().Max != 0.0)) dataAttribute = storeConstraint(Model.RangeConstraints.First(), dataAttribute); else dataAttribute = deletConstraint(Model.RangeConstraints.First().Id, dataAttribute); if (Model.PatternConstraints.Count > 0 && !String.IsNullOrEmpty(Model.PatternConstraints.FirstOrDefault().MatchingPhrase)) dataAttribute = storeConstraint(Model.PatternConstraints.First(), dataAttribute); else dataAttribute = deletConstraint(Model.PatternConstraints.First().Id, dataAttribute); if (Model.PatternConstraints.Count > 0 && !String.IsNullOrEmpty(Model.DomainConstraints.FirstOrDefault().Terms)) dataAttribute = storeConstraint(Model.DomainConstraints.First(), dataAttribute); else dataAttribute = deletConstraint(Model.DomainConstraints.First().Id, dataAttribute); #endregion DAM.UpdateDataAttribute(dataAttribute); } } else { Session["nameMsg"] = "Name already exist"; Session["Window"] = true; return View("AttributeManager", new DataAttributeManagerModel(Model)); } } } Session["Window"] = false; return RedirectToAction("AttributeManager"); }
public AttributePreviewStruct fill(DataAttribute dataAttribute, bool getConstraints) { this.Id = dataAttribute.Id; this.Name = dataAttribute.Name; this.Description = dataAttribute.Description; this.Unit.Id = dataAttribute.Unit.Id; this.Unit.Name = dataAttribute.Unit.Name; this.DataType = dataAttribute.DataType.Name; if (getConstraints) { if (dataAttribute.Constraints != null) { foreach (Constraint c in dataAttribute.Constraints) { c.Materialize(); this.Constraints.Add(c.Id, c.FormalDescription); } } } if (dataAttribute.UsagesAsVariable.Count > 0) this.inUse = true; else this.inUse = false; return this; }
public static MessageModel validateAttributeInUse(long Id, DataAttribute dataAttribute) { if (dataAttribute != null && dataAttribute.Id != 0) { if (dataAttribute.UsagesAsVariable.Count > 0) { try { return new MessageModel() { hasMessage = true, Message = "Can't save Variable Template " + dataAttribute.Name + " (" + Id + "), it's uesed by a Data Structure.", CssId = "inUse" }; } catch { return new MessageModel() { hasMessage = true, Message = "Something is wrong with Variable Template " + Id, CssId = "0" }; } } else { return new MessageModel(); } } else { if (Id == 0) { return new MessageModel(); } else { return new MessageModel() { hasMessage = true, Message = "Can't save Variable Template " + Id + ", it's uesed by a Data Structure.", CssId = "0" }; } } }
/// <summary> /// Creates a link between a <see cref="StructuredDataStructure"/> and <see cref="DataAttribute"/>. This link is known as <see cref="Variable"/>. /// In addition to what a variable inherits from the associated data attribute, it can have its own label, default and missing values, and optionality of its value. /// </summary> /// <param name="dataStructure">The structured data structure to be linked to the data attribute</param> /// <param name="dataAttribute">The data attribute to be used in a data structure as a variable</param> /// <param name="isValueOptional">Indicates whether the <see cref="VariableValue"/> associated to the variable is optional or not. This allows dataset to not provide data values for optional variables.</param> /// <param name="label">The display name of the variable. It may differ from the associated data attribute name. The variable label usually indicates the role of the data attribute in the structure. /// Its possible for a data structure to use a data attribute more than once by creating more than one variables, hence having different labels.</param> /// <param name="defaultValue">The default value of the associated variable values. Mainly considered for user interface purposes.</param> /// <param name="missingValue">A specific sentinel value that when is put into the variable values, means those values are missing and should not be considered data.</param> /// <param name="variableUnit">A specific unit for the variable. If not provided the unit of the <paramref name="dataAttibute"/> is used. /// If provided, its dimension must be equal to the dimension of the <paramref name="dataAttribute"/>'s unit.</param> /// <returns>A created and persisted variable object.</returns> public Variable AddVariableUsage(StructuredDataStructure dataStructure, DataAttribute dataAttribute, bool isValueOptional, string label, string defaultValue, string missingValue, string description, Unit variableUnit = null) { Contract.Requires(dataStructure != null && dataStructure.Id >= 0); Contract.Requires(dataAttribute != null && dataAttribute.Id >= 0); Contract.Requires((variableUnit == null && dataAttribute.Unit == null) || (variableUnit == null) || (variableUnit.Dimension == dataAttribute.Unit.Dimension)); Contract.Ensures(Contract.Result<Variable>() != null && Contract.Result<Variable>().Id >= 0); //StructuredDataStructureRepo.Reload(dataStructure); StructuredDataStructureRepo.LoadIfNot(dataStructure.Variables); int count = (from v in dataStructure.Variables where v.DataAttribute.Id.Equals(dataAttribute.Id) select v ) .Count(); //if (count > 0) // throw new Exception(string.Format("Data attribute {0} is already used as a variable in data structure {0}", dataAttribute.Id, dataStructure.Id)); Variable usage = new Variable() { DataStructure = dataStructure, DataAttribute = dataAttribute, MinCardinality = isValueOptional ? 0 : 1, // if there is no label provided, use the data attribute name and a sequence number calculated by the number of occurrences of that data attribute in the current structure Label = !string.IsNullOrWhiteSpace(label) ? label : (count <= 0 ? dataAttribute.Name : string.Format("{0} ({1})", dataAttribute.Name, count)), DefaultValue = defaultValue, MissingValue = missingValue, Description = description, Unit = (variableUnit != null ? variableUnit : dataAttribute.Unit), }; dataAttribute.UsagesAsVariable.Add(usage); dataStructure.Variables.Add(usage); using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository<Variable> repo = uow.GetRepository<Variable>(); repo.Put(usage); uow.Commit(); } return (usage); }
/// <summary> /// The method functions in a similar way to the <see cref="AddVariableUsage"/> method, but operates on a <see cref="Parameter"/> /// </summary> /// <param name="variableUsage"></param> /// <param name="dataAttribute"></param> /// <param name="isValueOptional"></param> /// <param name="label"></param> /// <param name="defaultValue"></param> /// <param name="missingValue"></param> /// <returns></returns> public Parameter AddParameterUsage(Variable variableUsage, DataAttribute dataAttribute, bool isValueOptional, string label, string defaultValue, string missingValue, string description) { Contract.Requires(variableUsage != null && variableUsage.DataAttribute.Id >= 0); Contract.Requires(dataAttribute != null && dataAttribute.Id >= 0); Contract.Ensures(Contract.Result<Parameter>() != null && Contract.Result<Parameter>().Id >= 0); VariableRepo.Reload(variableUsage); VariableRepo.LoadIfNot(variableUsage.Parameters); int count = (from pu in variableUsage.Parameters where pu.DataAttribute.Id.Equals(dataAttribute.Id) select pu ) .Count(); // support multiple use of a data attribute as a parameter in a variable context //if (count > 0) // throw new Exception(string.Format("Data attribute {0} is already used as a parameter in conjunction with variable {1} in data structure {2}", dataAttribute.Id, variableUsage.DataAttribute.Id, variableUsage.DataStructure.Id)); Parameter usage = new Parameter() { DataAttribute = dataAttribute, Variable = variableUsage, MinCardinality = isValueOptional ? 0 : 1, // if there is no label provided, use the data attribute name and a sequence number calculated by the number of occurrences of that data attribute in the current usage Label = !string.IsNullOrWhiteSpace(label) ? label : (count <= 0 ? dataAttribute.Name : string.Format("{0} ({1})", dataAttribute.Name, count)), DefaultValue = defaultValue, MissingValue = missingValue, Description = description }; dataAttribute.UsagesAsParameter.Add(usage); variableUsage.Parameters.Add(usage); using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository<Parameter> repo = uow.GetRepository<Parameter>(); repo.Put(usage); uow.Commit(); } return (usage); }
public DataAttributeModel(DataAttribute dataAttribute, bool showConstraints = false) { Id = dataAttribute.Id; Name = dataAttribute.Name; ShortName = dataAttribute.ShortName; Description = dataAttribute.Description; ShowConstraints = showConstraints; DataType = new DataTypeItemModel(dataAttribute.DataType); Unit = new UnitItemModel(dataAttribute.Unit); dataTypeManager.Repo.Get().OrderBy(dt => dt.Name).ToList().ForEach(dt => DataTypes.Add(new DataTypeItemModel(dt))); unitManager.Repo.Get().OrderBy(u => u.Name).ToList().ForEach(u => Units.Add(new UnitItemModel(u))); RangeConstraints = new List<RangeConstraintModel>(); DomainConstraints = new List<DomainConstraintModel>(); PatternConstraints = new List<PatternConstraintModel>(); dataAttribute.Constraints.ToList().Where(c => c.GetType().Equals(typeof(RangeConstraint))).ToList().ForEach(rc => RangeConstraints.Add(RangeConstraintModel.Convert((RangeConstraint)rc, Id))); dataAttribute.Constraints.ToList().Where(c => c.GetType().Equals(typeof(PatternConstraint))).ToList().ForEach(pc => PatternConstraints.Add(PatternConstraintModel.Convert((PatternConstraint)pc, Id))); dataAttribute.Constraints.ToList().Where(c => c.GetType().Equals(typeof(DomainConstraint))).ToList().ForEach(dc => DomainConstraints.Add(DomainConstraintModel.Convert((DomainConstraint)dc, Id))); if (dataAttribute.UsagesAsVariable != null && dataAttribute.UsagesAsVariable.Count > 0) InUse = true; if (dataAttribute.Constraints.Count > 0) { foreach (Constraint c in dataAttribute.Constraints) { if (c is RangeConstraint) { RangeConstraints.Add(RangeConstraintModel.Convert((RangeConstraint)c, Id)); } if (c is PatternConstraint) { PatternConstraints.Add(PatternConstraintModel.Convert((PatternConstraint)c, Id)); } if (c is DomainConstraint) { DomainConstraints.Add(DomainConstraintModel.Convert((DomainConstraint)c, Id)); } } } }
/// <summary> /// Create ValueValidationManager of a Variable /// </summary> /// <remarks></remarks> /// <param name="varName"></param> /// <param name="dataType"></param> /// <param name="optional"></param> /// <param name="variable"></param> /// <returns></returns> private ValueValidationManager createValueValidationManager(string varName, string dataType, bool optional, DataAttribute variable) { ValueValidationManager vvm = new ValueValidationManager(varName, dataType, optional, Info.Decimal); return vvm; }
public DataAttribute UpdateDataAttribute(DataAttribute entity) { Contract.Requires(entity != null, "provided entity can not be null"); Contract.Requires(entity.Id >= 0, "provided entity must have a permanent ID"); Contract.Ensures(Contract.Result<DataAttribute>() != null && Contract.Result<DataAttribute>().Id >= 0, "No entity is persisted!"); using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository<DataAttribute> repo = uow.GetRepository<DataAttribute>(); repo.Put(entity); // Merge is required here!!!! uow.Commit(); } return (entity); }
public AttributePreviewStruct fill(DataAttribute dataAttribute) { return this.fill(dataAttribute, true); }
public DataAttribute CreateDataAttribute(string shortName, string name, string description, bool isMultiValue, bool isBuiltIn, string scope, MeasurementScale measurementScale, DataContainerType containerType, string entitySelectionPredicate, DataType dataType, Unit unit, Methodology methodology, Classifier classifier, ICollection<AggregateFunction> functions, ICollection<GlobalizationInfo> globalizationInfos, ICollection<Constraint> constraints, ICollection<ExtendedProperty> extendedProperies ) { Contract.Requires(!string.IsNullOrWhiteSpace(shortName)); Contract.Requires(dataType != null && dataType.Id >= 0); Contract.Requires(unit != null && unit.Id >= 0); Contract.Ensures(Contract.Result<DataAttribute>() != null && Contract.Result<DataAttribute>().Id >= 0); DataAttribute e = new DataAttribute() { ShortName = shortName, Name = name, Description = description, IsMultiValue = isMultiValue, IsBuiltIn = isBuiltIn, Scope = scope, MeasurementScale = measurementScale, ContainerType = containerType, EntitySelectionPredicate = entitySelectionPredicate, DataType = dataType, Unit = unit, Methodology = methodology, AggregateFunctions = functions, GlobalizationInfos = globalizationInfos, Constraints = constraints, ExtendedProperties = extendedProperies, }; if (classifier != null && classifier.Id > 0) e.Classification = classifier; using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository<DataAttribute> repo = uow.GetRepository<DataAttribute>(); repo.Put(e); uow.Commit(); } return (e); }
// create read attributes in bpp public void CreateAttributes(ref DataTable mappedAttributes) { foreach (DataRow mapAttributesRow in mappedAttributes.Rows) { DataContainerManager attributeManager = new DataContainerManager(); DataTypeManager dataTypeManager = new DataTypeManager(); UnitManager unitManager = new UnitManager(); DataAttribute attribute = new DataAttribute(); // values of the attribute attribute.ShortName = mapAttributesRow["ShortName"].ToString(); attribute.Name = mapAttributesRow["Name"].ToString(); attribute.Description = mapAttributesRow["Description"].ToString(); attribute.IsMultiValue = false; attribute.IsBuiltIn = false; //attribute.Owner = "BMM"; attribute.Scope = ""; attribute.MeasurementScale = MeasurementScale.Categorial; ////////!!!!!!!!fromMapping?????????????????? attribute.ContainerType = DataContainerType.ReferenceType; attribute.EntitySelectionPredicate = ""; attribute.DataType = dataTypeManager.Repo.Get(Convert.ToInt64(mapAttributesRow["DataTypeId"])); attribute.Unit = unitManager.Repo.Get(Convert.ToInt64(mapAttributesRow["UnitId"])); attribute.Methodology = null; attribute.Classification = null; attribute.AggregateFunctions = null; attribute.GlobalizationInfos = null; attribute.Constraints = null; attribute.ExtendedProperties = null; DataAttribute dataAttribute = new DataAttribute(); DataAttribute existAttribute = attributeManager.DataAttributeRepo.Get(a => attribute.Name.Equals(a.Name) && attribute.ShortName.Equals(a.ShortName) && attribute.Unit.Id.Equals(a.Unit.Id) && attribute.DataType.Id.Equals(a.DataType.Id) ).FirstOrDefault(); // if attribute not exists (name, shortName) then create if (existAttribute == null) { dataAttribute = attributeManager.CreateDataAttribute( attribute.ShortName, attribute.Name, attribute.Description, attribute.IsMultiValue, attribute.IsBuiltIn, attribute.Scope, attribute.MeasurementScale, attribute.ContainerType, attribute.EntitySelectionPredicate, attribute.DataType, attribute.Unit, attribute.Methodology, attribute.Classification, attribute.AggregateFunctions, attribute.GlobalizationInfos, attribute.Constraints, attribute.ExtendedProperties ); } else { dataAttribute = existAttribute; } // add attributeId to the mappedAttributes Table mapAttributesRow["AttributeId"] = dataAttribute.Id; } }