public static IOrderedQueryable <T> CreateOrderedQuery <T>( this List <SortInfo> sortInfoList, IQueryable <T> query) where T : class { bool flag = true; IOrderedQueryable <T> source = (IOrderedQueryable <T>)null; foreach (SortInfo sortInfo in sortInfoList) { string mapPropertyName = PropertyMapCollection.GetMapPropertyName <T>(sortInfo.Field); try { if (flag) { source = !(sortInfo.Dir.ToLower() == "asc") ? query.OrderByDescending <T>(mapPropertyName) : query.OrderBy <T>(mapPropertyName); flag = false; } else { source = !(sortInfo.Dir.ToLower() == "asc") ? source.ThenByDescending <T>(mapPropertyName) : source.ThenBy <T>(mapPropertyName); } } catch (ArgumentException ex) { } } return(source); }
// Methods public static void AddMap(Type objType, PropertyMap map) { PropertyMapCollection maps = null; if (!s_maps.TryGetValue(objType, out maps)) { lock (s_SyncObj) { if (!s_maps.TryGetValue(objType, out maps)) { maps = new PropertyMapCollection(); if (!maps.Contains(map.Key)) { maps.Add(map); } s_maps.Add(objType, maps); } } } else if (!maps.Contains(map.Key)) { lock (s_SyncObj) { if (!maps.Contains(map.Key)) { maps.Add(map); } } } }
public Item(MappingInstructionType instructionType,MappingDirection direction, Object source, Type sourceType, Object target, Type targetType, PropertyMapCollection propertyMapList) { this.InstructionType = instructionType; this.Direction = direction; this.Source = source; this.SourceType = sourceType; this.Target = target; this.TargetType = targetType; this.PropertyMapList = propertyMapList; }
public static object GetPropertyMapInObject(PropertyMapCollection maps, object root, string propertyMapName) { object target = root; string[] strArray = propertyMapName.Split(new char[1] { '_' }); if (strArray.Length > 1) { for (int index1 = 0; index1 < strArray.Length - 1; ++index1) { string index2 = strArray[index1]; target = maps[index2].Property.GetValue(target); } } return(target); }
public static PropertyMap FindColumnByPropertyName <TEntity>(string propertyName, PropertyMapCollection pmc) { if (pmc == null && pmc.Count == 0) { return(null); } foreach (var p in pmc) { if (p.Property.PropertyName == propertyName) { return(p); } } return(null); }
public static string FindColumnNameByPropertyName <TEnttiy>(string propertyName, PropertyMapCollection pmc) { var p = FindColumnByPropertyName <TEnttiy>(propertyName, pmc); if (p != null && p.Column != null) { return(p.Column.ColumnName); } return(propertyName); }
public Expression <Func <TEntity, bool> > TranslateFilter <TEntity>( bool processPersianChars = true) where TEntity : class { QueryObject <TEntity> queryObject = new QueryObject <TEntity>(); ParameterExpression parameterExpression = Expression.Parameter(typeof(TEntity), "entity"); foreach (FilterData filter in this.Filters) { if (filter.Filters != null && filter.Filters.Any <FilterData>()) { Expression <Func <TEntity, bool> > query = new FilterInfo() { Logic = filter.Logic, Filters = filter.Filters }.TranslateFilter <TEntity>(true); if (string.IsNullOrWhiteSpace(this.Logic)) { queryObject.And(query); } else if (this.Logic.ToLower() == "and") { queryObject.And(query); } else { queryObject.Or(query); } } else if (processPersianChars && filter.Value != null && (filter.Value.Contains("ي") || filter.Value.Contains("ك") || filter.Value.Contains("ی") || filter.Value.Contains("ک"))) { FilterInfo filterInfo = new FilterInfo() { Logic = "or" }; filterInfo.Filters.Add(filter); string str = ""; if (filter.Value.Contains("ي") || filter.Value.Contains("ك")) { str = filter.Value.Replace("ي", "ی").Replace("ك", "ک"); } else if (filter.Value.Contains("ی") || filter.Value.Contains("ک")) { str = filter.Value.Replace("ی", "ي").Replace("ک", "ك"); } filterInfo.Filters.Add(new FilterData() { Field = filter.Field, Logic = filter.Logic, Operator = filter.Operator, Value = str }); Expression <Func <TEntity, bool> > query = filterInfo.TranslateFilter <TEntity>(false); if (string.IsNullOrWhiteSpace(this.Logic)) { queryObject.And(query); } else if (this.Logic.ToLower() == "and") { queryObject.And(query); } else { queryObject.Or(query); } } else { string mapPropertyName = PropertyMapCollection.GetMapPropertyName <TEntity>(filter.Field); Expression bodyExpression = FilterInfo.CreateBodyExpression(parameterExpression, mapPropertyName, filter.Operator, filter.Value); if (bodyExpression != null) { Expression <Func <TEntity, bool> > query = Expression.Lambda <Func <TEntity, bool> >(bodyExpression, parameterExpression); if (string.IsNullOrWhiteSpace(this.Logic)) { queryObject.And(query); } else if (this.Logic.ToLower() == "and") { queryObject.And(query); } else { queryObject.Or(query); } } } } return(queryObject.Query()); }