1

I have this linq query

List<Details> DetailList = new List<Details>();

DetailList = (from areadetails in context.AreaDetails.Where(x => (bool)x.IsActive && x.Area == area) 
                                  join jobdetails in context.JobDetails.Where(x => x.IsActive) on jobdetails.BuildDetailID equals areadetails.BuildDetailID
                                  select new Details
                                  {
                                      Area = areadetails.AreaName,
                                      JobLink = (jobdetails.EJ2JobLink != null) ? jobdetails.JobLink + "/console" : null,
                                      JobId = (jobdetails.EJ2JobLink != null) ? jobdetails.JobLink.Split('/').Last() : null
                                  }).ToList();

JobLink = job/it/development/41

I have to get the job id(41) from the link. When I have run this(JobLink.Split('/').Last()) separately in console application get correct job id from the link.When I used in linq.

I got an exception like this:

LINQ to Entities does not recognize the method 'System.String Format(System.String, System.Object[])' method, and this method cannot be translated into a store expression.

Anyone know why? Anyone know an alternative way of doing this to make it work?

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
Gokul P
  • 31
  • 4
  • 2
    Possible duplicate of [LINQ to Entities does not recognize the method 'System.String Format(System.String, System.Object, System.Object)'](https://stackoverflow.com/questions/10079990/linq-to-entities-does-not-recognize-the-method-system-string-formatsystem-stri) – Stephen Kennedy Jun 12 '19 at 19:56

1 Answers1

0

Either use the approach mentioned in the answer that @Stephen Kennedy linked in the comment to this question or split the string by some way that can be mapped to a database query - this should work:

 JobId = (jobdetails.EJ2JobLink != null) ? jobdetails.JobLink.Substring(jobDetails.JobLink.Length - EntityFunctions.Reverse(e.jobDetails.JobLink).IndexOf('/') + 1) : null

/Edit: Updated as LastIndexOf is not supported.

Christoph Sonntag
  • 4,459
  • 1
  • 24
  • 49