1

Here's what I'm looking for-- a way in .NET to pass in 1) an everyday .NET object/POCO 2) a string-based query to run against said object (in whatever query language) that returns the result of the query applied to the object.

I've already tried the following with no success

  • Finding a way to serialize a string into a LINQ query against an object. What i can't figure out about this is why LinqPad can do it but the code they use isn't freely available.
  • Using an OData library

I'm having a hard time believing that there isn't a simple (especially Linq-based) way to query objects via a string. In javascript, i could pass the object into an eval-ed function context therefore execute a JS string against an object.

Roslyn is off the table. I need this to work in Mono.

Ideas?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Micah
  • 10,295
  • 13
  • 66
  • 95
  • 1
    You should be able to use [*Dynamic LINQ*](http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx) for that. – Sergey Kalinichenko Sep 11 '13 at 01:51
  • 1
    As I understand it LinqPad compiles the code into IL using CodeDom a sort of predecessor of Roslyn. – Aron Sep 11 '13 at 03:20
  • have you looked at NHibernate? – Quibblesome Sep 11 '13 at 12:50
  • @Quibblesome i'm not looking for an ORM, if thats what you're getting after – Micah Sep 11 '13 at 15:01
  • Nope, just that NHibernate maps to POCOs and also offers HQL queries (string based queries) you can execute against a session object. However I have no idea about serializing the LINQ (IIRC it added LINQ support v2.x). Also as its open source I'd figure it would play reasonably nice with Mono. – Quibblesome Sep 11 '13 at 15:22

1 Answers1

0

Dynamic LINQ sounds good. If you would prefer to use javascript you could use a script engine. See parse and execute JS by C#

Community
  • 1
  • 1
franzo
  • 1,379
  • 1
  • 15
  • 30
  • dynamic linq would allow me to specify a where clause or an orderby clause but not necessarily an entire query against an obj, right? i'm going after the entire query – Micah Sep 11 '13 at 15:00
  • and i would rather avoid embedding a js engine if at all possible. if it gets to that i'd rather rewrite the existing code to node – Micah Sep 11 '13 at 15:02