0

I need to create a query that returns data with column name (without square brackets) as indicated in the code below. How can I do that?

var query = db.Customers
 .Where("City = @0 and Orders.Count >= @1", "London", 10)
 .OrderBy("CompanyName")
 .Select("new(CompanyName as [Company Name])");

1 Answers1

0

When you need to make LINQ queries dynamic you may need to drop down the Expression Tree layer. The reason for this is that virtually everything there is dynamic... It allows you to build queries on the fly but.... it takes a while to learn and it is tedious in my opinon.

This is what was done here: https://gist.github.com/400553/6562ebb3cf2767d6c1ad9474d6f04691ab6ca412

JWP
  • 6,672
  • 3
  • 50
  • 74
  • The select string is generated in code. I never now which columns are selected. – Thorgeir Berre Oct 14 '14 at 19:10
  • I'm sorry, I didn't fully realize the problem... In this case you will have to drop down one layer.... Let me post the answer... – JWP Oct 14 '14 at 19:14
  • I am trying to avoid Expression trees:-). Using the Dynamic LINQ Library, this works fine as long as column names are without spacees. Anybody know how to handle this? – Thorgeir Berre Oct 15 '14 at 06:43
  • Ya I don't blame you, I spent about two months once learning Expression trees and decided it wasn't for me. It has to be the worst parsing engine ever invented; although, some folks have really taken to it...like the LINQ Pad guys... – JWP Oct 15 '14 at 13:03