Page 1 of 1
Error: Cannot use "timestamp(6)" type value in "TimeSpan" type argument
Posted: Tue 15 Apr 2014 08:04
by DarkPreacher
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.
Re: Error: Cannot use "timestamp(6)" type value in "TimeSpan" type argument
Posted: Thu 17 Apr 2014 10:56
by MariiaI
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/ ... pping.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).