I have the following POCO class, where Date is defined as a string and will always conform to the following format 'yyyyMMdd'
public class Price {
[AutoIncrement]
public int Id {get;set;}
public string Date {get;set;}
public decimal Price {get;set;}
}
I would like to run a OrmLite query using Linq which retrieves all prices with a date greater or equal to a certain request string PriceDateGreaterThan parameter.
ie.
var prices = Db.Select<Price>().Where(ar => ar.PriceDate >= request.PriceDateGreaterThan).ToList();
Given PriceDate & PriceDateGreaterThan are both of type string (& not int or DateTime), how can I run this query using OrmLite?
As .NET's BCL doesn't define comparison operators for String
(e.g. <=,<,>,=>
) you can't use a typed API for this so you'd need to use custom SQL, e.g:
var q = Db.From<Price>();
q.Where(q.Column<Price>(x => x.Date) + " >= {0}", priceDateGreaterThan);
var prices = db.Select(q);