-3
"((IEnumerable)sourceData).Cast().Select(ob => 
    new 
    { 
        SenderId = "Expo-HSE-01", 
        IssueId = ob.IncidentNo.Value, 
        IssuePointId = String.Join(",", ((IEnumerable)ob.TypeofIncident)
            .Cast()
            .Select(ip => ip.Value)), 
        IssueTypeId = "Issue-HSE-General", 
        ZoneId = ob.Location.LocationCode.Value 
    }"

Getting above query as string need to execute this at runtime.

Yuriy Faktorovich
  • 67,283
  • 14
  • 105
  • 142
  • 1
    related : https://stackoverflow.com/questions/16794537/how-to-execute-string-formatted-linq-query-in-c-sharp-mvc3 , https://stackoverflow.com/questions/821365/how-to-convert-a-string-to-its-equivalent-linq-expression-tree – xdtTransform May 27 '20 at 12:59
  • Everything executes at runtime. What do you mean? – itsme86 May 27 '20 at 14:24
  • So what is the type of sourceData, and what would you like to get as result? – Harald Coppoolse May 27 '20 at 14:32
  • @itsme86 OP gets a string and needs to convert it into executable code. – nilsK May 27 '20 at 14:51
  • @Santosh what have you tried so far? ([how-to-ask page](https://stackoverflow.com/help/how-to-ask)) – nilsK May 27 '20 at 14:52
  • @itsme86 Need to execute linq query getting as string in c# And the query is dynamic , each time it changes based on the requirement. Then the output from query will be dynamic , we wont be having any models for that since the aim is to make this code generic. – Santhosh Markandaiah May 28 '20 at 16:38
  • @itsme86 the source is of JObject type as of now. and casting as dynamic to handle different types/objects of data from different sources – Santhosh Markandaiah May 28 '20 at 16:40
  • @nilsK Am working on generic solution to handle any source of data to destination expected payload(different names from src, mismatch in params count). So my idea is to send the destination required param as linq query from UI (tool) and execute that at run time. – Santhosh Markandaiah May 28 '20 at 16:43
  • @itsme86 got the solution from, (https://stackoverflow.com/questions/5399967/parse-string-into-a-linq-query) Using CSharpScript namespace , now able to implement as expected. Thanks for your queries and suggestions Guy's. – Santhosh Markandaiah May 28 '20 at 16:47
  • @nilsK got the solution from, (https://stackoverflow.com/questions/5399967/parse-string-into-a-linq-query) Using CSharpScript namespace , now able to implement as expected. Thanks for your queries and suggestions Guy's. – Santhosh Markandaiah May 28 '20 at 16:48

1 Answers1

0

Parse string into a LINQ query

CSharpScripting able to execute the code getting as string.