Unions and dates

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
damon.cognito
Posts: 50
Joined: Wed 22 Jul 2009 09:30

Unions and dates

Post by damon.cognito » Fri 14 Aug 2009 12:10

I am trying to join two queries together but I am getting the error:

Code: Select all

'The type arguments for method 'System.Linq.Enumerable.Union(System.Collections.Generic.IEnumerable, System.Collections.Generic.IEnumerable)' cannot be inferred from the usage. Try specifying the type arguments explicitly.'
I boiled an example down to the simplest form:

Code: Select all

var query = ((from table1 in entity.table1
             select new
             {
                 Date = table1.StampStart
             }).Union(from table2 in entity.table2
             select new
             {
                 Date = table2.StampEnd,
             }));
With tables

Code: Select all

CREATE TABLE "table1"
(
  "OIDtable1" serial NOT NULL,
  "StampStart" timestamp(0) without time zone NOT NULL
);

CREATE TABLE "table2"
(
  "OIDtable2" serial NOT NULL,
  "StampEnd" timestamp(0) without time zone
);
The only difference is the one of the date fields is 'not null'. The table definitions cannot change, so does anyone know a workaround please?

Using latest .dotConnect for Postgresql.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Mon 17 Aug 2009 10:53

The problem is that DateTime and DateTime? are different types and there is no implicit cast between these.
I recommend you to use the following query:

Code: Select all

var query = ((from t1 in entity.table1
  select new {
    Date = (DateTime?)t1.StampStart
  }).Union(from t2 in entity.table2
    select new {
      Date = t2.StampEnd
    }));

damon.cognito
Posts: 50
Joined: Wed 22 Jul 2009 09:30

Post by damon.cognito » Thu 17 Sep 2009 09:33

Yes, that was perfect - thanks!

Post Reply