Search code examples
c#simple.data

How can I cast to IEnumerable<Guid> in simple.data?


I have this query in simple.data

var db = Database.Open();
IEnumerable<Guid> recetas = db.Factura
    .All()
    .Where(db.Factura.ObraSocialPlan_id == obraSocialPlanId)
    .Select(db.Factura.Id)
    .Cast<Guid>();

And I'm getting

Cannot implicitly convert type 'Simple.Data.SimpleRecord' to 'System.Guid'

How should I change the query?


Solution

  • You can't do this to an enumerable, but you can materialise it to a list like this:

    var db = Database.Open();
    IEnumerable<Guid> recetas = db.Factura
        .All()
        .Where(db.Factura.ObraSocialPlan_id == obraSocialPlanId)
        .Select(db.Factura.Id)
        .ToScalarList<Guid>();
    

    If you want laziness, so you can pass the enumerable somewhere without having actually run the query, please raise an issue on the GitHub page: http://github.com/markrendle/Simple.Data/issues

    Thanks.