This project has moved and is read-only. For the latest updates, please go here.


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


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;
        var query = from d in new SQLinq<Something>()
                    where d.Key != Guid.NewGuid()
                    select d;
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


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:
    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; }

wrote Oct 19, 2013 at 2:22 AM

wrote Oct 19, 2013 at 2:23 AM