예제 #1
0
 public ColumnMap GetColumnMap(string propertyName)
 {
     if (ColumnsMap.ContainsKey(propertyName))
     {
         return(ColumnsMap[propertyName]);
     }
     if (_baseModelMap != null)
     {
         return(_baseModelMap.GetColumnMap(propertyName));
     }
     return(null);
 }
예제 #2
0
        public static Dictionary <string, object> GetModelValues <TModel>(TModel model)
        {
            //TODO:Tratar exceções
            Type     modelType = model.GetType();
            ModelMap modelMap  = ModelMap.GetModelMap(modelType);
            Dictionary <string, object> modelValues = new Dictionary <string, object>();

            foreach (string propertyName in modelMap.GetPropertiesNamesList())
            {
                try
                {
                    object value = modelType.GetProperty(propertyName).GetValue(model, null);
                    if (value != null && modelMap.GetColumnMap(propertyName).DataType == DataAnnotations.ERBridge.DataType.Xml)
                    {
                        XmlDocument xml = new XmlDocument();
                        xml.InnerXml = Commons.Utilities.ClassToXML.SerializeObject(value, propertyName);
                        value        = xml.FirstChild.InnerXml;
                    }
                    else if (modelMap.GetColumnMap(propertyName).DataType == DataAnnotations.ERBridge.DataType.DateTime && DateTime.MinValue.Equals(value))
                    {
                        value = null;
                    }

                    ReferenceMapInfo referenceMap = modelMap.GetReferencesMap(propertyName);
                    if (value != null && referenceMap != null)
                    {
                        object keyValue = value.GetType().GetProperty(referenceMap.ReferenceKey).GetValue(value, null);
                        modelValues.Add(propertyName + "." + referenceMap.ReferenceKey, keyValue);
                    }
                    else
                    {
                        modelValues.Add(propertyName, value);
                    }
                }
                catch (Exception ex) {
                    Commons.Utilities.Logger.Error(ex);
                }
            }
            return(modelValues);
        }
예제 #3
0
        public ColumnMap GetMappedColumnMap(string propertyName)
        {
            ColumnMap mappedColumnMap = GetColumnMap(propertyName);

            if (mappedColumnMap == null)
            {
                string[] propertyParts = propertyName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
                if (propertyParts.Length > 1)
                {
                    ReferenceMapInfo reference = GetReferencesMapList().FirstOrDefault(r => r.Property == propertyParts[0]);
                    if (reference != null)
                    {
                        ModelMap referenceModelMap = ModelMap.GetModelMap(reference.ReferencedModelType);
                        if (referenceModelMap != null)
                        {
                            mappedColumnMap = referenceModelMap.GetColumnMap(propertyName.Remove(0, (propertyParts[0] + ".").Length));
                        }
                    }
                }
            }
            return(mappedColumnMap);
        }