Created
September 23, 2014 09:02
-
-
Save rustyJ4ck/d5efc345c05ec3c2f91c to your computer and use it in GitHub Desktop.
StationLoader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// | |
/// project App.Lib | |
/// | |
namespace App.Lib.Models.Station | |
using Sqlite; | |
using System.Linq; | |
using System.Linq.Expressions; | |
using Mono.Linq.Expressions; | |
class StationLoader() | |
{ | |
public TableQuery<Station> GetStationsTable() | |
{ | |
return DB.Connection.Table<Station>(); | |
} | |
public IEnumerable<App.Lib.Models.Station.Station> GetStations() | |
{ | |
var where = PredicateBuilder.False<InforkomApp.Models.Station.Station>(); | |
where = where.OrElse(s => s.Id > 500); | |
// other conditions... | |
var result = GetStationsTable() | |
.Where(where) | |
.Take(30) | |
.ToList() | |
; | |
Console.WriteLine("Count {0}", result.Count); | |
return result; | |
} | |
} | |
/// | |
/// project App.Android | |
/// | |
namespace App.Android | |
class Test() { | |
void TestMethod() | |
{ | |
// prints `count 30`, it's OK | |
GetStations(); | |
// prints `count 1000`, that's FAIL | |
// Why linq `where` and `take` was not used in this example? | |
new App.Lib.Models.Station.StationLoader().GetStations(); | |
} | |
public IEnumerable<App.Lib.Models.Station.Station> GetStations() { | |
// same as in StationLoader class, but | |
// GetStationsTable = new InforkomApp.Models.Station.StationLoader().GetStationsTable() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment