Best way to write Dynamic Query with dynamic result with Linq or Expression Tree?

Your question is asking for a Linq, specifically a Linq to Sql, implementation of how to achieve your dynamic queries But consider what Linq to Sql is for. The main benefits that jump to mind of Linq to SQL are: Strongly typed queries (catch errors at compile time) Strongly typed results. Meaning nice pre-written classes (in Linq to SQL's case, pre generated) Now, if you're doing "Select" statments and always returning an actual mapped table, then there's no reason you can't use the Dynamic Linq library But if you're returning abitary non mapped results, there's no point in using LINQ, indeed it won't let you DataContext.

ExecuteQuery(string query) The DataContext class does have an ExecuteQuery method, but you unfortunately you cannot return specify dynamic as the T :-( Linq to SQL and Stored Procedures Lastly, LINQ to SQL can map to Stored Procedure.So you could have a stored proc that take a qeury as an argument, like your example. However, I believe it's got the same limitations of ExecuteQuery in terms of the types in can result, though don't hold me to that I'd have a look at that as your final option, and explore the sproc in the Linq to SQL designer returning either anonymous, dynamic, or a mapped type.

Probably not I was going to suggest Dynamic Linq but as your "Edit" states that won't do for you. In that case I'd say the answer to your question is "There is no best way". Is Linq the best choice for this?

Your question is asking for a Linq, specifically a Linq to Sql, implementation of how to achieve your dynamic queries. But consider what Linq to Sql is for. The main benefits that jump to mind of Linq to SQL are: Strongly typed queries (catch errors at compile time) Strongly typed results.

Meaning nice pre-written classes (in Linq to SQL's case, pre generated) Now, if you're doing "Select" statments and always returning an actual mapped table, then there's no reason you can't use the Dynamic Linq library. But if you're returning abitary non mapped results, there's no point in using LINQ, indeed it won't let you.DataContext. ExecuteQuery(string query) The DataContext class does have an ExecuteQuery method, but you unfortunately you cannot return specify dynamic as the T :-( Linq to SQL and Stored Procedures Lastly, LINQ to SQL can map to Stored Procedure.

So you could have a stored proc that take a qeury as an argument, like your example. However, I believe it's got the same limitations of ExecuteQuery in terms of the types in can result, though don't hold me to that. I'd have a look at that as your final option, and explore the sproc in the Linq to SQL designer returning either anonymous, dynamic, or a mapped type.

Thanks for your answer. Is Entity Framework good for his purpose? Can we write ESQL like `HQL' in – Nima Sep 15 at 4:53 I'm not entirely familiar with EF so not sure.

However, I am familiar with N and know that HQL won't allow for what you want either. HQL essentially is the equivalent here of Dynamic Linq, in that it lets you use strings to build queries which actually reference strongly typed objects. Your pivot example wouldn't work in that case.

– andy Sep 15 at 10:25.

I was going to suggest Dynamic Linq but as your "Edit" states that won't do for you. In that case I'd say the answer to your question is "There is no best way". Is Linq the best choice for this?

Your question is asking for a Linq, specifically a Linq to Sql, implementation of how to achieve your dynamic queries. But consider what Linq to Sql is for. Strongly typed results.

Now, if you're doing "Select" statments and always returning an actual mapped table, then there's no reason you can't use the Dynamic Linq library. But if you're returning abitary non mapped results, there's no point in using LINQ, indeed it won't let you. Lastly, LINQ to SQL can map to Stored Procedure.

So you could have a stored proc that take a qeury as an argument, like your example. However, I believe it's got the same limitations of ExecuteQuery in terms of the types in can result, though don't hold me to that. I'd have a look at that as your final option, and explore the sproc in the Linq to SQL designer returning either anonymous, dynamic, or a mapped type.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions