I have come across the LinqToExcel library and have been playing around with it a bit. I seem to be mis-understanding how the querying works. I have created a simple worksheet with some customer info. Using LinqPad, I've setup my query as so:
void Main()
{
string path = @"E:\Documents\LINQPad\LINQPad Queries\LinqToExcel\Customers.xlsx";
var excel = new ExcelQueryFactory(path);
// Mappings and Transforms:
excel.AddMapping<Customer>(c => c.Contact, "Contact Person");
excel.AddMapping<Customer>(c => c.CompanyName, "Company Name");
excel.AddMapping<Customer>(c => c.IsPreferred, "Preferred");
excel.AddTransformation<Customer>(c => c.IsPreferred, cellValue => cellValue == "Yes");
// Query:
var preferrdCompanies = from c in excel.Worksheet<Customer>("Customers")
where c.IsPreferred // this has no effect?
orderby c.CompanyName
select new { c.CompanyName, c.Contact, c.IsPreferred };
// Display:
preferrdCompanies.Dump("Preferred Customers:");
}
// Define other methods and classes here
class Customer
{
public string Contact { get; set; }
public string CompanyName { get; set; }
public bool IsPreferred { get; set; }
}
For some reason, the predicate is not being applied. The transform to true(bool) from the text "Yes" is working. If I write:
preferrdCompanies.ToList().Where(c => c.IsPreferred).Dump("Preferred Customers:");
I get the filtered list as you would expect. I've been looking for a simple error in my code but it throws no exceptions and I can't find anything obviously wrong, so I guess I just don't understand how the querying functions?
Any answer/explanation would be appreciated, thanks.