Error: Cannot use "timestamp(6)" type value in "TimeSpan" type argument

Error: Cannot use "timestamp(6)" type value in "TimeSpan" type argument

Postby DarkPreacher » Tue 15 Apr 2014 08:04

Code: Select all
using (var db = new DataContext())
{
  List<ExtendedJournal>eventList0 = (from j in db.Journal
                        join jp in db.JournalPerson on j.IdJournal equals jp.IdJournal
                        join p in db.Person on jp.IdPerson equals p.IdPerson
                        where idsPerson.Contains(jp.IdPerson) &
                       (j.DatetimeEnd.Equals(null) | DateTime.Now - j.DatetimeStart < date)
                        orderby j.DatetimeStart descending
                        orderby j.DatetimeEnd descending
                        select new ExtendedJournal {Journal = j, Person = p}).ToList();
...
return eventList0;
}

DatetimeStart and DatetimeEnd fields are of type 'timestamp without time zome' in the database.
I have no idea I'm doing something wrong or is this a bug in linq.
DarkPreacher
 
Posts: 1
Joined: Tue 15 Apr 2014 07:37

Re: Error: Cannot use "timestamp(6)" type value in "TimeSpan" type argument

Postby MariiaI » Thu 17 Apr 2014 10:56

Error: Cannot use "timestamp(6)" type value in "TimeSpan" type argument

This error is reproducible in our environment in case when the entity properties 'DatetimeStart' and 'DatetimeEnd' (that correspond the fields with the 'timestamp without time zome' type) are mapped to the TimeSpan data type in the model. The PostgreSQL data type 'timestamp' should be mapped to the DateTime data type, please refer to
http://www.devart.com/linqconnect/docs/?postgresql_datatypemapping.html

The solutions for you:
1) use the PostgreSQL data types, that could be mapped to TimeSpan (see here) to be able to work with such queries
Code: Select all
...
(j.DatetimeEnd.Equals(null) | DateTime.Now - j.DatetimeStart < date)
...
2) map the 'DatetimeStart' and 'DatetimeEnd' properties to DateTime data type and do not use such comparisons ("DateTime.Now - j.DatetimeStart < date") in LINQ queries (if it is possible for your scenario).
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17


Return to dotConnect for PostgreSQL