1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | /* * Search method - Executes custom query only joining to location table if required **/ public void Search( int pItemId, int ? pAreaId, int ? pLocationId) { DB.Location.Table locationTable = DB.Location.Table.INSTANCE; DB.StockSet.Table stockSetTable = DB.StockSet.Table.INSTANCE; Sql.Condition condition = stockSetTable.ItemId == pItemId; bool joinLocn = false ; if (pLocationId != null ) //Dynamically create where condition condition = condition.And(stockSetTable.LocnId == pLocationId.Value); else if (pAreaId != null ) { joinLocn = true ; condition = condition.And(locationTable.AreaId == pAreaId.Value); } Sql.IResult result = Sql.Query.Select(stockSetTable.Qty, stockSetTable.Value) .From(stockSetTable) .JoinIf(joinLocn, locationTable, locationTable.Id == stockSetTable.LocnId) // Note JoinIf(...) only includes join if bool value is true .Where(condition) .ExecuteUncommitted(); for ( int index = 0; index < result.Count; index++) { //TODO: read result } } |