Skip to content

Instantly share code, notes, and snippets.

@rustyJ4ck
Created September 23, 2014 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rustyJ4ck/d5efc345c05ec3c2f91c to your computer and use it in GitHub Desktop.
Save rustyJ4ck/d5efc345c05ec3c2f91c to your computer and use it in GitHub Desktop.
StationLoader
///
/// 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