I m trying to write a ling 2 entity left join query between 2 tables where the join column has different datatypes in the tables. Hence I use the new keyword to perform string conversion using SqlFunctions.StringConvert() function.
But this throws an error saying “This function can only be invoked from LINQ to Entities.”
The sql query would look something like this…
select distinct j.jobid from jobs j
left join jobfilters jf
on j.jobid = jf.jobid
left join vwbranchmaster bm
on bm.branchid = jf.jobfilterkey
In this query, bm.branchid is of int and jobfilterkey is nvarchar. Unfortunately, Branchmaster is in a external DB so we cant modify the DB columns.
The L2E query looks like this, (please note that dt is DataTable converted to Enumerable type)
from J in dt
join JFBRegion in JobFilter on J.Field<Guid>("JobId") equals JFBRegion.JobID into JFBRegion_join
from JFBRJ in JFBRegion_join.DefaultIfEmpty()
join BRMAS in BranchMaster on new { JobFilterKey = JFBRJ.JobFilterKey } equals new { JobFilterKey = SqlFunctions.StringConvert((decimal)BRMAS.BranchID) } into BMASJF_join
from BMASJF in BMASJF_join.DefaultIfEmpty()
Please let me know what I m doing wrong here or if this is possible to do at all.
Thanks.
If you’re performing this query on a
DataTablethen this is notLinq To Entitiesbecause you perform in in .NET memory. You need to perform the query withEntity Frameworkcontext.