0

How I can edit SQL Command from IQueryable? I need edit ON of JOIN, because Linq to Entities dont allow use IEqualityComparer.

I need to edit the command string and then put back in IQueryable.

user2965241
  • 53
  • 1
  • 5
  • 1
    I seriously doubt that it is possible, and know for sure that even if it is doable, it isn't going to be pretty. If you are looking to do something that complicated, you should probably rethink your strategy. Consider posting the actual problem that you are facing to avoid getting an advise on an X-Y problem. – Sergey Kalinichenko Nov 20 '13 at 20:27
  • I need edit ON of JOIN. – user2965241 Nov 20 '13 at 21:38
  • You can assume that I read your question, so there's no point to summarize it one more time for me. Editing `ON` of `JOIN` is useless unless it helps you retrieve data in some way that is not possible *without* such editing. If you describe the retrieval that you are trying to do by means of editing `ON` of `JOIN`, there may be a path to a solution that does not involve such editing. – Sergey Kalinichenko Nov 20 '13 at 21:43
  • 1
    I need this: SELECT * FROM myTable t1 INNER JOIN myTable t2 ON t1.time = t2.time + 1 OR t1.time = t2.time + 2 OR t1.time = t2.time + 3; – user2965241 Nov 20 '13 at 21:58
  • You can try this: `var res = from t1 in context.myTable join t2 in context.myTable on t1.time==SqlFunctions.DateAdd("day", 1, t2.time) || t1.time==SqlFunctions.DateAdd("day", 2, t2.time) || t1.time==SqlFunctions.DateAdd("day", 3, t2.time) select ... ` (add the actual select there). – Sergey Kalinichenko Nov 20 '13 at 22:08
  • time isnt datetime... time is a column integer of myTable. I dont want execute in realtime the query, I want add in IQueryable. – user2965241 Nov 20 '13 at 22:10
  • Attempt number 2: `var res = from t1 in context.myTable join t2 in context.myTable on t1.time==t2.time+1 || t1.time==t2.time+2 || t1.time==t2.time+3 select new {First=t1,Second=t2};` This remains an `IQueryable`, but it's on an anonymous type. – Sergey Kalinichenko Nov 20 '13 at 22:14
  • What if I need to make a JOIN myTable again with res? Sorry my bad english. – user2965241 Nov 21 '13 at 00:35
  • You can continue on, like this: `var res2 = from r in res join t3 in context.myTable on ...` and so on. – Sergey Kalinichenko Nov 21 '13 at 00:39
  • Is generating the error: The name X is not in scope on the left side of the equals. He did not let me use ==, Equals only. Nor let me use | |. – user2965241 Nov 21 '13 at 06:11

0 Answers0