Z. Asif
Z. Asif

Reputation: 43

DbExpressionBinding requires an input expression with a collection ResultType. Parameter name: input

I've a big problem with my linq query

            var t = from tl in _GxEntities.T_L
                             join td in _GxEntities.T_D on (int)tl.fld_rdRequestfk equals td.fld_rqID_pk
                             join tpd in _GxEntities.T_P_D on (int)td.fld_rqID_pk equals tpd.fld_pdRequest_fk                                 
                             where tpd.fld_pdda == null
                                && tpd.fld_pdSU_fk == tl.fld_rdSU_fk
                                && td.fld_rqstatus != 1
                                && tl.fld_rcid != null
                                && tl.loc_id == UsrProfilService.loc_id
                                && tl.fld_rcid.Any(x=> tblRvGxFr.Select(c=>c.Nte).Contains(x.ToString()))
                             group tl by new
                             {
                                 tl.fld_rcid,
                                 tl.fld_rdSU_fk,
                                 tl.fld_rdtRequested_Q,
                                 tl.loc_id
                             } into q
                             select new RVSyntheseDetailModel()
                             {
                                 RC_ID = q.Key.fld_rcid,
                                 SU = (int)q.Key.fld_rdSU_fk,
                                 Ts = (int)q.Sum(k => k.fld_rdtRequested_Q),
                                 LOC_ID = (short)q.Key.loc_id
                             };

        return t.ToList();

If I comment && tl.fld_rcid.Any(x=> tblRvGxFr.Select(c=>c.Nte).Contains(x.ToString())) this part I don't have any problem. tblRvGxFr is from another entities and looks like this :

var dateLimit = DateTime.Now.Date.AddMonths(-1);

var tblRtvGrxFr = from tgx in _FtEntities.TL_RV_FR_GX
 where tgx.RV_D_LIM_RET > dateLimit && tgx.RV_N_IDT_DAP != null && tgx.RV_LOC_ID == SqlFunctions.StringConvert((double)UsrProfilService.loc_id)
  select new RVSyntheseRrModel()
  {
      Nte = tgx.RV_ETET,
      Tr = tgx.RV_TR,
      Filiere = tgx.RV_T_PRD,
      Lib_art = tgx.RV_L_ART,
      SU = tgx.RV_N_IDT_DAP,
      Qte_demand = (int?)tgx.RT_Q_DEM_RET ?? 0,
      Ord = 0,
      Tcs = 0,
      AfA = 0,
      PrA = 0,
      Exped = 0,
      Loc_Id = tgx.RV_LOC_ID,
      Reason = tgx.RV_REASON
  };

Can you help me? Why do I get this error "DbExpressionBinding requires an input expression with a collection ResultType. Parameter name: input"?

And if I change this condition to : && tblRvGxFr.Select(i => i.Nte).Contains(tl.fld_rcid) I've this error : Unable to process the type 'GX.ViewModels.RVSyntheseRrModel[]', because it has no known mapping to the value layer.

Upvotes: 4

Views: 9530

Answers (1)

Ivan Stoev
Ivan Stoev

Reputation: 205769

Normally you would use something like this

&& tblRvGxFr.Any(c => c.Nte.Contains(tl.fld_rcid))

However LINQ to Entities does not support queries involving different DbContexts. So you need to grab the Ntes into a local list/array

var nteList = tblRvGxFr.Select(c => c.Nte).ToList();

and then use this instead:

&& nteList.Any(nte => nte.Contains(tl.fld_rcid))

Hope the Nte list is not big, because otherwise the SQL query will be quite big and inefficient. But AFAIK no other multi context solution exists.

Upvotes: 5

Related Questions