private IEnumerable<SelectPart> Include(SelectSqlBuilder bulder, TableContext mainTableContext, TypeMappingInfo typeMapping, string include) { var fields = include.Split('.'); var currentType = typeMapping; var context = mainTableContext; foreach (var navigationField in fields) { var navProperty = (NavigationPropertyMapping) currentType.GetProperty(navigationField); if (navProperty.Table is PrimitiveListTable) { var listContext = GetTableContext(navProperty.Table, "S"); bulder.SelectAll(listContext); bulder.LeftOuterJoin(context, listContext, ((EntityTable)context.Table).IdentityColumn.ColumnName, navProperty.Table.Columns.First().ColumnName); yield return new ExpansionPart { Table = navProperty.Table, CollectingType = currentType, CollectingProperty = navProperty }; break; } //todo: no primitive collections totally and no inheritance lookup var targetType = navProperty.TargetType; var tableInfo = targetType.Tables.OfType<EntityTable>().First(); var nextcontext = GetTableContext(tableInfo, "S"); bulder.SelectAll(nextcontext); if (navProperty.Host == ReferenceHost.Parent) { bulder.LeftOuterJoin(context, nextcontext, navProperty.ColumnName, tableInfo.IdentityColumn.ColumnName); } else if (navProperty.Host == ReferenceHost.Child) { bulder.LeftOuterJoin(context, nextcontext, ((EntityTable)context.Table).IdentityColumn.ColumnName, navProperty.ColumnName); } else throw new NotImplementedException(); yield return new SubTypePart { Type = targetType, Tables = new[] {tableInfo}, CollectingType = currentType, CollectingProperty = navProperty }; currentType = targetType; context = nextcontext; } }