A Runtime Query question

I have a object collection which contains a collection of properties. The number and name/type of these properties aren't know until runtime. Different versions of the object collection have the same properties however. I'd like to use LINQ for queries if possible.

The only way I can see to do this is to generate a schema from a 'template' collection for compile time support and use this in conjunction with a custom LINQ provider if necessary. Is this possible?

Any thoughts appreciated.

Guy

[506 byte] By [Guy05] at [2007-12-23]
# 1

It sounds like you have used a scheme similar to the datatable in ADO in your custom object implementation. You may want to consider trying some of the ideas from the LINQ to DataSet querying against your custom objects. Thus the syntax may result in something like the following:

var results = from i in MyObject
where i.Item<string>("prop1")="foo"
select new{i.Item<int>("ID"), i.item<string>("Description")}

Note, you will loose the strong typing since your object isn't strongly typed to begin with. Also, the above code is not debugged so the syntax may not work. Please post your code if you are able to get this to work.

Jim Wooley
http://devauthority.com/blogs/jwooley

jwooley at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,LINQ Project General...
# 2
Thank Jim,

I didn't try your idea although it seems reasonable. I've decided to implement a custom query engine (a bit scary). Partly because I want a simple (target audience) query expression and it also gives me the opportunity to optimise a multithread version as the object collection can be quite large.

Guy05 at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,LINQ Project General...

Visual Studio Orcas

Site Classified