Data Directive BPM C# Linq Help

We’re also running on 10.1.400.17, and it compiles for me without any error. I copied your new code and replaced the variables with hardcoded values.

o=> o.Company == “My Company” && o.HDCaseNum == 123

Do you have another “select new” in your code? maybe there’s a conflict between your anonymous types.

1 Like

#Yep - As Joel states - if you make an object of a certain anonymous type - you cant change it later.

If I did, then I would have gotten the same error with the original code. see earlier post. In any case, I concluded what support has stated two years ago, Left out joins are not supported in LINQ BPM. Therefore, I used a equal join which works but not like a left outer join. Thank you for taking the time, see my equal join code below:

  /* start of old code */
		// MGA - 17-JUN-2018, Added inner join (because left outer join not supported) for OrderDtl.PickListComment 
		// MGA - 17-JUN-2018, Added inner join (becasue left outer join not supported) for Customer.CreditHold
	 var OrderHedDtlVar = (from o in Db.OrderHed.With(LockHint.NoLock)
				join od in Db.OrderDtl.With(LockHint.NoLock) on o.OrderNum equals od.OrderNum
      join cu in Db.Customer.With(LockHint.NoLock) on o.CustNum equals cu.CustNum 
     where o.Company == TaskListVar.Company && o.HDCaseNum == CaseNumber &&  od.OrderLine==1 
       
     //orderby l.TaskSeqNum ascending
			 //orderby l.TaskSeqNum descending
           select new 
           {
              o.OrderNum, o.RequestDate, o.DocTotalCharges, od.PickListComment, cu.CreditHold

           }).FirstOrDefault();

		/* old code */

			 if (OrderHedDtlVar != null)
			 {
			 	TaskListVar["rsiOrderNum_c"] = OrderHedDtlVar.OrderNum;
       // MGA - 05/04/2018 - Added the RequestDate (ShipBy) from the OrderHed table, requested by M. Fitzpatrick.  
       TaskListVar["rsiRequestDate_c"] = OrderHedDtlVar.RequestDate;
       TaskListVar["rsiOrderHedDocTotalCharges_c"] = OrderHedDtlVar.DocTotalCharges;
       TaskListVar["rsiOrderDtlPickListComment_c"] = OrderHedDtlVar.PickListComment;
				 TaskListVar["rsiCustomerCreditHold_c"] = OrderHedDtlVar.CreditHold;
			}

The error is due to the anonymous types that you are trying to return.

Have you tried this?

 /* Start new code */
 var OrderHedVar = (from o in Db.OrderHed.Where (o=> o.Company == TaskListVar.Company && o.HDCaseNum == CaseNumber)
			// *** Add left outer join to OrderDtl
		     join od in Db.OrderDtl.With(LockHint.NoLock) 
             on new { o.Company, o.OrderNum } equals new { od.Company, od.OrderNum }
     into oodj 
     from joins in oodj.DefaultIfEmpty()

			// *** 
    
 //where o.Company == TaskListVar.Company && o.HDCaseNum == CaseNumber   

       select new 
       {
          o.OrderNum, 
          o.RequestDate,
          o.DocTotalCharges

       });

  // end new code

or if that doesn’t work how about

 /* Start new code */
 var OrderHedVar = (from o in Db.OrderHed.Where (o=> o.Company == TaskListVar.Company && o.HDCaseNum == CaseNumber)
			// *** Add left outer join to OrderDtl
		     join od in Db.OrderDtl.With(LockHint.NoLock) 
             on new { o.Company, o.OrderNum } equals new { od.Company, od.OrderNum }
     into oodj 
     from joins in oodj.DefaultIfEmpty()

			// *** 
    
 //where o.Company == TaskListVar.Company && o.HDCaseNum == CaseNumber   

       select
       {
          OrderNum = o.OrderNum, 
          RequestDate = o.RequestDate,
          DocTotalCharges = o.DocTotalCharges

       });

  // end new code

Yes, I have

I have sometime next week to further experiment with LINQ left outer joins. Thanks you again for your suggestions. I will keep you posted. Best regards.

Its turned out that the error was coming from when I was attempted to reference a column from the query but from the following:

 if (OrderHedVar != null)
{
	TaskListVar["rsiOrderNum_c"] = OrderHedVar.OrderNum; <-- error occurs at this line. 

}
`

I am not sure how to fix the error or the code?
Error Detail

Description: There is at least one compilation error.
Details:
Error CS1061: ‘System.Linq.IQueryable<AnonymousType#1>’ does not contain a definition for ‘OrderNum’ and no extension method ‘OrderNum’ accepting a first argument of type ‘System.Linq.IQueryable<AnonymousType#1>’ could be found (are you missing a using directive or an assembly reference?) [GetTaskList.Post.Set_Quote_Number.cs(281,50)]
Error CS1061: ‘System.Linq.IQueryable<AnonymousType#1>’ does not contain a definition for ‘RequestDate’ and no extension method ‘RequestDate’ accepting a first argument of type ‘System.Linq.IQueryable<AnonymousType#1>’ could be found (are you missing a using directive or an assembly reference?) [GetTaskList.Post.Set_Quote_Number.cs(283,58)]
Error CS1061: ‘System.Linq.IQueryable<AnonymousType#1>’ does not contain a definition for ‘DocTotalCharges’ and no extension method ‘DocTotalCharges’ accepting a first argument of type ‘System.Linq.IQueryable<AnonymousType#1>’ could be found (are you missing a using directive or an assembly reference?) [GetTaskList.Post.Set_Quote_Number.cs(284,70)]
Program: Epicor.Customization.dll
Method: PrepareException
Line Number: 99
Column Number: 13

You could try
select new{ OrderNum = o.OrderNum, RequestDate = o.RequestDate, DocTotalCharges = o.DocTotalCharges });

Thank you. But I tried your suggestion and it resulted in the same error message.

I added the ".FirstOrDefault(); to the end of the “select new” statement and it worked.