Left Join statement in LINQ to entites

0

I tried to do a left join in LINQ as follows:

(from opr in db.Operacao
join vol in db.Volume on new { VOL_CODBAR = opr.OPR_CODBAR } equals new { VOL_CODBAR     = vol.VOL_CODBAR } into vol_join
from vol in vol_join.DefaultIfEmpty()
select new {
  opr.OPR_IDX,
  opr.OPR_CODEMP,
  opr.OPR_CODFIL,
  opr.OPR_NUMVEI,
  opr.OPR_TIPOPR,
  vol.VOL_TITLE
})

But at runtime, and the exception is generated:

  

LINQ to Entities does not recognize the 'System.Collections.Generic.IEnumerable 1[ImprotecSistemas.PackLocator.PackServer.DataAccess.vwObtemFuncionario] DefaultIfEmpty[Operacao](System.Collections.Generic.IEnumerable 1 [ImprotecSistemas.PackLocator.PackServer.DataAccess.Operacao]' method, which can not be converted into a storage expression. >

Here's what I want in SQL:

Select *
From operacao opr
     left join volumes vol on vol.VOL_CODBAR = OPR.OPR_CODBAR

I'm using Entity Framework 3.5 C #

    
asked by anonymous 22.12.2014 / 18:10

1 answer

1

Entity Framework 3.5 does not have LEFT JOIN for queries with Linq. But there is another way to do this, described here: link

I believe that in your case, the code should look something like this:

from opr in db.Operacao
select new 
{
  Operacao = opr,
  Volumes = opr.Volumes.Where(vol => vol.VOL_CODBAR = opr.OPR_CODBAR)
};
    
04.04.2015 / 03:03