private string PredicateForPrimitiveList(SelectSqlBuilder builder, Table tbl, TableContext context) { var listContext = GetTableContext(tbl, "T"); builder.InnerJoin(context, listContext, ((EntityTable) context.Table).IdentityColumn.ColumnName, tbl.Columns[0].ColumnName); return builder.GetEquality(listContext, tbl.Columns[1].ColumnName, builder.GetNextParameter()); }
private void BuildSelectPredicate(SelectSqlBuilder builder, TableContext initialContext, TypeMappingInfo type, string s) { var fields = s.Split('.'); var currentType = type; var context = initialContext; string predicate; foreach (var navigationField in fields.Take(fields.Length - 1)) { var navProperty = (NavigationPropertyMapping) type.GetProperty(navigationField); var table = navProperty.Table; if (table is PrimitiveListTable) { builder.Where(PredicateForPrimitiveList(builder, table, context)); return; } currentType = navProperty.TargetType; //todo: no primitive collections totally and no inheritance lookup var tableInfo = currentType.Tables.OfType<EntityTable>().First(); var nextcontext = GetTableContext(tableInfo, "T"); if (navProperty.Host == ReferenceHost.Parent) { builder.InnerJoin(context, nextcontext, navProperty.ColumnName, tableInfo.IdentityColumn.ColumnName); } else if (navProperty.Host == ReferenceHost.Child) { builder.InnerJoin(context, nextcontext, ((EntityTable)context.Table).IdentityColumn.ColumnName, navProperty.ColumnName); } else throw new NotImplementedException(); context = nextcontext; } var property = currentType.GetProperty(fields.Last()); var tbl = property.Table; if (tbl is PrimitiveListTable) { predicate = PredicateForPrimitiveList(builder, tbl, context); } else { predicate = builder.GetEquality(GetTableContext(tbl, tbl == initialContext.Table ? "M" : "T"), property.ColumnName, builder.GetNextParameter()); } //todo: think of context and inheritance builder.Where(predicate); }