Hector Minaya
Hector Minaya

Reputation: 1705

SubSonic Outer Join

There seems to be a Bug with the Outer Join statement in SubSonic 3, or maybe it's just my ignorance, but the following craps out:

var Objeto = from t in Table1.All()
             join su in table2.All() on t.Id equals su.Id
             join tab2 in Table1.All() on t.PId equals tab2.Id into gj
             from j in gj.DefaultIfEmpty()
             select new
             {
                 t.Field1,
                 SN = su.Field123,
                 PTN = (j == null ? null : j.FieldABC)
              };

With:

The expression of type 'System.Linq.IQueryable` xxxx is not a sequence

Upvotes: 1

Views: 434

Answers (2)

CodingWithSpike
CodingWithSpike

Reputation: 43718

Reviving an old topic here, but for those that come searching along later, there is a different syntax that seems to work correctly in SubSonic3 for a left outer join.

Instead of the Linq expression from the original post that does a join ... into ... Rewrite it to:

var Objeto = from t in Table1.All()
         join su in table2.All() on t.Id equals su.Id
         from j in Table1.All().Where(x => x.Id == t.PId).DefaultIfEmpty()
         select new
         {
             t.Field1,
             SN = su.Field123,
             PTN = (j == null ? null : j.FieldABC)
          };

The key part being: from j in Table1.All().Where(x => x.Id == t.PId).DefaultIfEmpty() which will do the outer join, instead of the traditional join ... into

Hopefully this helps!

Upvotes: 1

bastianneu
bastianneu

Reputation: 2069

They already had issues with IQueryable:

Blog Entry

Just for your Information...

Upvotes: 0

Related Questions