tags:

views:

79

answers:

1
var query2 = (from p in db.posts
                     where (p.date) == (from q in db.posts
                                        select q.date).Max()
                     select p.date).SingleOrDefault();

id = Convert.ToInt32(query2);

I'm getting this error when trying to get the max Date from posts table, is there an alternative way?

+2  A: 

TIMESTAMP is an internal SQL Server datatype stored as a 8-byte blob. It has nothing to do with date/time - it's just an internal counter, really.

It's actually deprecated even - use the rowversion datatype instead (as of SQL Server 2008 and up).

From SQL Server Books online:

The SQL Server timestamp data type has nothing to do with times or dates. SQL Server timestamps are binary numbers that indicate the relative sequence in which data modifications took place in a database. The timestamp data type was originally implemented to support the SQL Server recovery algorithms.

You cannot use byte array bytes in aggregates, as the error message says clearly.

I would assume there is another DATETIME column in your table somewhere??

Check out this excellent Timestamps vs. Datetime data types article for more insights.

Marc

marc_s
I changed from timestamp to Datetime and it worked.I'm new to LINQ/Sql and in MYsql timestamp worked fine.Thanks for ur answer
Joe
@Joe: no problem. Yes, the name "TIMESTAMP" can be quite misleading! That's why they're changing it to "ROWVERSION" - seems more intuitive
marc_s