Date parameter in MySQL query

102 views
Skip to first unread message

Magnus Olsson

unread,
Jan 9, 2011, 11:56:55 AM1/9/11
to DbLinq
Hello,

I am new to DBlinq and I have a problem and I don't know if it is
because I'm doing something wrong, if it is because a bug or "not
implemented" :)
I am using MySql.

The problem is when I try to use dates in my query.
The code:
var ids = from i in ctx.Markets
where i.DateScheduled > DateTime.Now
select i.MarketId;
Console.WriteLine(ids.Count());


A MySqlException is thrown:
"You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ':52:15.9545502+01:00)' at line 3"

When I inspect the command it reads like:
"SELECT COUNT(*)\r\nFROM `MyDatabase`.`Markets`\r\nWHERE
(`DateScheduled` > 2011-01-09T17:52:15.9545502+01:00)"

As you can see the date parameter seems to lacks the enclosing ''.
I shouldn't have to do the enclosing myself? If so where would I
easily do that. If not in which type can I edit so that the value is
enclosed. (
I just started using DBLinq and to browse the src-tree so I don't find
very easily yet :)

Thanks in advance
/Magnus Olsson

Sadık Eser

unread,
Jan 10, 2011, 3:23:59 AM1/10/11
to dbl...@googlegroups.com
In dblinq queries, using datetime.now or similar parameters some times couses error.
if you use

DateTime d = DateTime.Now;
var ids = from i in ctx.Markets
                 where i.DateScheduled > d
                 select i.MarketId;


it will works.

Best regards
Sadık Eser

2011/1/9 Magnus Olsson <magn...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "DbLinq" group.
To post to this group, send email to dbl...@googlegroups.com.
To unsubscribe from this group, send email to dblinq+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dblinq?hl=en.


Reply all
Reply to author
Forward
0 new messages