2

Closed

Errors on DateTime.Now and Guid.NewGuid() within Where clause

description

public class Something
{
    public Guid Key { get; set; }
    public long Count { get; set; }
    public DateTime DateCreated { get; set; }        
}
 
        var query = from d in new SQLinq<Something>()
                    where d.DateCreated <= DateTime.Now
                    select d;
 
        Console.WriteLine(query.ToSQL().ToQuery());
 
        var query = from d in new SQLinq<Something>()
                    where d.Key != Guid.NewGuid()
                    select d;
 
        Console.WriteLine(query.ToSQL().ToQuery());
 
Both of these blow up on me. Great stuff though!
Closed Oct 19, 2013 at 2:23 AM by crpietschmann
Support for "DateTime.Now", "DateTime.UtcNow" and "Guid.NewGuid()" have been added within a Where clause

comments

crpietschmann wrote Apr 27, 2013 at 7:03 PM

The issue is with the Property (DateTime.Now) and Method (Guid.NewGuid()) not with the DateTime or Guid types.

Using the following form will work for now:
    [TestMethod]
    public void DateTime_001()
    {
        var test = DateTime.Now;
        var query = from d in new SQLinq<DateTime_001_Class>()
                    where d.Date > test
                    select d;

        var result = (SQLinqSelectResult)query.ToSQL();

        Assert.AreEqual("[Date] > @sqlinq_1", result.Where);
        Assert.AreEqual(1, result.Parameters.Count);
        Assert.AreEqual(test, result.Parameters["@sqlinq_1"]);
    }

    private class DateTime_001_Class
    {
        public int ID { get; set; }
        public DateTime Date { get; set; }
    }