public ISelector CreateExceptSelector(string[] paths) { var exceptInfo = GetInfos(paths); if (RootMapping.HasJoinRelateModel) { var jSelector = new JoinSelector(); foreach (var kvs in fieldInfoDict) { if (!exceptInfo.Contains(kvs.Value)) { jSelector.SetAliasDataField(kvs.Value as AliasDataFieldInfo); } } return(jSelector); } var nSelector = new Selector(); foreach (var kvs in fieldInfoDict) { if (!exceptInfo.Contains(kvs.Value)) { nSelector.SetSelectField(kvs.Value); } } return(nSelector); }
public static JoinSelector ComposeSelector(Dictionary <string, Selector> selectors) { var joinSelector = new JoinSelector(); foreach (var selector in selectors) { foreach (var item in selector.Value.selectList) { var info = item; var aliasName = $"{selector.Key}_{info.FieldName}"; var alias = new AliasDataFieldInfo(info, aliasName, selector.Key); //alias.AliasTableName = selector.Key; joinSelector.SetAliasDataField(alias); } } return(joinSelector); }
public static JoinSelector ComposeSelector(Dictionary <string, Selector> selectors) { JoinSelector joinSelector = new JoinSelector(); foreach (KeyValuePair <string, Selector> selector in selectors) { foreach (DataFieldInfo item in selector.Value.selectList) { DataFieldInfo info = item; string aliasName = string.Format("{0}_{1}", selector.Key, info.FieldName); AliasDataFieldInfo alias = new AliasDataFieldInfo(info, aliasName, selector.Key); //alias.AliasTableName = selector.Key; joinSelector.SetAliasDataField(alias); } } return(joinSelector); }
public override ISelector CreateSelector(string[] fullPaths) { Dictionary <string, List <string> > dict = new Dictionary <string, List <string> >(); foreach (string fullPath in fullPaths) { int index = fullPath.IndexOf(".", StringComparison.Ordinal); if (index < 0) { if (mapDict.ContainsKey(fullPath)) { if (!dict.TryGetValue(fullPath, out List <string> list)) { list = new List <string>(); dict.Add(fullPath, list); } if (!list.Contains(string.Empty)) { list.Add(string.Empty); } } else { throw new LambdaParseException(LambdaParseMessage.ExpressionFieldPathError, fullPath); } } else { string name = fullPath.Substring(0, index); string path = fullPath.Substring(index); if (mapDict.ContainsKey(name)) { if (!dict.TryGetValue(name, out List <string> list)) { list = new List <string>(); dict.Add(name, list); } if (!list.Contains(path)) { list.Add(path); } } else { throw new LambdaParseException(LambdaParseMessage.ExpressionFieldPathNotExists, fullPath); } } } Dictionary <string, Selector> selectDict = new Dictionary <string, Selector>(); foreach (KeyValuePair <string, List <string> > kvs in dict) { IMap map = mapDict[kvs.Key]; string alias = aliasDict[kvs.Key]; Selector selector = map.CreateSelector(kvs.Value.ToArray()) as Selector; if (selector == null) { throw new LambdaParseException(LambdaParseMessage.NotSupportRelateEnityJoinSelect); } selectDict.Add(alias, selector); } JoinSelector joinSelector = Selector.ComposeSelector(selectDict); return(joinSelector); }
public ISelector CreateSelector(string[] paths) { var allPaths = RewritePaths(paths); var hash = new HashSet <DataFieldInfo>(); var stable = new HashSet <string>(); foreach (var path in allPaths) { if (fieldInfoDict.TryGetValue(path, out var info)) { if (!hash.Contains(info)) { hash.Add(info); var index = path.LastIndexOf('.'); if (index > 0) { var t = path.Substring(0, index); if (!stable.Contains(t)) { stable.Add(t); var sInfos = GetFieldInfoForSingleField(t); foreach (var sInfo in sInfos) { if (!hash.Contains(sInfo)) { hash.Add(sInfo); } } } } } continue; } if (tableInfoDict.TryGetValue(path, out var tInfos)) { foreach (var tInfo in tInfos) { stable.Add(path); if (!hash.Contains(tInfo)) { hash.Add(tInfo); } } continue; } throw new LightDataException(string.Format(SR.CanNotFindTheSpecifiedFieldViaPath, path)); } if (RootMapping.HasJoinRelateModel) { var jSelector = new JoinSelector(); foreach (var dataFieldInfo in hash) { var info = (AliasDataFieldInfo)dataFieldInfo; jSelector.SetAliasDataField(info); } return(jSelector); } var nSelector = new Selector(); foreach (var item in hash) { nSelector.SetSelectField(item); } return(nSelector); }
private void LoadJoinRelate() { LoadEntityMapping(RootMapping, null); var joinSelector = new JoinSelector(); var items = new List <RelationItem>(); // var relationItemDict = new Dictionary<string, RelationItem>(); var tIndex = 0; foreach (var link in linkList) { var sItems = link.GetRelationItems(); foreach (var item in sItems) { if (!items.Contains(item)) { if (item.FieldMapping == null && tIndex != 0) { continue; } item.AliasName = "T" + tIndex; tIndex++; items.Add(item); // relationItemDict.Add(item.CurrentFieldPath, item); } } } var rootItem = items[0]; mapDict.Add(items[0].CurrentFieldPath, items[0]); var rootInfoList = new List <DataFieldInfo>(); foreach (var field in RootMapping.DataEntityFields) { var info = new DataFieldInfo(field); var aliasName = $"{rootItem.AliasName}_{info.FieldName}"; var alias = new AliasDataFieldInfo(info, aliasName, rootItem.AliasName); joinSelector.SetAliasDataField(alias); rootInfoList.Add(alias); fieldInfoDict.Add($"{items[0].CurrentFieldPath}.{field.IndexName}", alias); } tableInfoDict.Add(items[0].CurrentFieldPath, rootInfoList.ToArray()); for (var i = 1; i < items.Count; i++) { var mItem = items[i]; mapDict.Add(mItem.CurrentFieldPath, mItem); var fieldMapping = mItem.FieldMapping; var mapping = fieldMapping.RelateMapping; DataFieldExpression expression = null; var rItem = mapDict[mItem.PrevFieldPath]; var mAlias = rItem.AliasName; var rAlias = mItem.AliasName; var relations = fieldMapping.CreateDataFieldInfoRelations(mAlias, rAlias); foreach (var relation in relations) { var mInfo = relation.MasterInfo; var rInfo = relation.RelateInfo; var keyExpression = new DataFieldOnMatchExpression(mInfo, rInfo, QueryPredicate.Eq); expression = DataFieldExpression.And(expression, keyExpression); } var infoList = new List <DataFieldInfo>(); foreach (var field in mapping.DataEntityFields) { var info = new DataFieldInfo(field); var aliasName = $"{rAlias}_{info.FieldName}"; var alias = new AliasDataFieldInfo(info, aliasName, rAlias); joinSelector.SetAliasDataField(alias); infoList.Add(alias); fieldInfoDict.Add($"{mItem.CurrentFieldPath}.{field.Name}", alias); } tableInfoDict.Add(mItem.CurrentFieldPath, infoList.ToArray()); var connect = new JoinConnect(JoinType.LeftJoin, expression); var model = new EntityJoinModel(mapping, rAlias, connect, null, null, JoinSetting.None); selector = joinSelector; models.Add(model); } }
void LoadJoinRelate() { LoadEntityMapping(this.rootMapping, null); JoinSelector joinSelector = new JoinSelector(); List <RelationItem> items = new List <RelationItem>(); Dictionary <string, RelationItem> relationItemDict = new Dictionary <string, RelationItem>(); int tindex = 0; foreach (RelationLink link in linkList) { RelationItem[] sitems = link.GetRelationItems(); foreach (RelationItem item in sitems) { if (!items.Contains(item)) { if (item.FieldMapping == null && tindex != 0) { continue; } item.AliasName = "T" + tindex; tindex++; items.Add(item); relationItemDict.Add(item.CurrentFieldPath, item); } } } //if (this.rootMapping != items [0].DataMapping) { // throw new LightDataException (RE.RelationMapEntityMappingError); //} RelationItem rootItem = items[0]; mapDict.Add(items[0].CurrentFieldPath, items[0]); List <DataFieldInfo> rootInfoList = new List <DataFieldInfo>(); foreach (DataFieldMapping field in this.rootMapping.DataEntityFields) { DataFieldInfo info = new DataFieldInfo(field); string aliasName = string.Format("{0}_{1}", rootItem.AliasName, info.FieldName); AliasDataFieldInfo alias = new AliasDataFieldInfo(info, aliasName, rootItem.AliasName); //alias.AliasTablesName = rootItem.AliasName; joinSelector.SetAliasDataField(alias); rootInfoList.Add(alias); fieldInfoDict.Add(string.Format("{0}.{1}", items[0].CurrentFieldPath, field.IndexName), alias); } tableInfoDict.Add(items[0].CurrentFieldPath, rootInfoList.ToArray()); for (int i = 1; i < items.Count; i++) { RelationItem mitem = items[i]; mapDict.Add(mitem.CurrentFieldPath, mitem); SingleRelationFieldMapping fieldMapping = mitem.FieldMapping; DataEntityMapping mapping = fieldMapping.RelateMapping; DataFieldExpression expression = null; //DataFieldInfoRelation [] relations = fieldMapping.GetDataFieldInfoRelations (); RelationItem ritem = mapDict[mitem.PrevFieldPath]; string malias = ritem.AliasName; string ralias = mitem.AliasName; DataFieldInfoRelation[] relations = fieldMapping.CreateDataFieldInfoRelations(malias, ralias); foreach (DataFieldInfoRelation relation in relations) { DataFieldInfo minfo = relation.MasterInfo; //minfo.AliasTableName = malias; DataFieldInfo rinfo = relation.RelateInfo; //rinfo.AliasTableName = ralias; DataFieldMatchExpression keyExpression = new DataFieldMatchExpression(minfo, rinfo, QueryPredicate.Eq); expression = DataFieldExpression.And(expression, keyExpression); //expression = DataFieldExpression.And (expression, minfo == rinfo); } List <DataFieldInfo> infoList = new List <DataFieldInfo>(); foreach (DataFieldMapping field in mapping.DataEntityFields) { DataFieldInfo info = new DataFieldInfo(field); string aliasName = string.Format("{0}_{1}", ralias, info.FieldName); AliasDataFieldInfo alias = new AliasDataFieldInfo(info, aliasName, ralias); //alias.AliasTableName = ralias; joinSelector.SetAliasDataField(alias); infoList.Add(alias); fieldInfoDict.Add(string.Format("{0}.{1}", mitem.CurrentFieldPath, field.Name), alias); } tableInfoDict.Add(mitem.CurrentFieldPath, infoList.ToArray()); JoinConnect connect = new JoinConnect(JoinType.LeftJoin, expression); EntityJoinModel model = new EntityJoinModel(mapping, ralias, connect, null, null, JoinSetting.None); this.selector = joinSelector; this.models.Add(model); } }