XML Serializable IQueryable<T>/Expression Tree
Is there any classes built in to .NET that will convert an expression tree or an 开发者_JS百科IQueryable<T>
to XML?
Not directly, no. IQuerable<T>
is an interface, and as such, there can be many implementations behind it, each of them serializing differently.
That said, you could try and serialize the Expression
that the IQueryable
interface (the base of IQueryable<T>
) exposes through the Expression
property.
The problem there is that the Expression
class and it's subclasses are not serializable, so you would have to create a structure that is a mirror of the Expression
class (and all of its subclasses, and there are many) and then serialize that. Fortunately, there is the Expression Tree Serialization project on MSDN which might help you.
Even then, you still won't have things like provider information, etc. This may or may not impact what you are trying to do.
However, if all you need is to set the expression tree on an existing IQueryable<T>
implementation, this should suffice.
精彩评论