开发者

XML Serializable IQueryable<T>/Expression Tree

开发者 https://www.devze.com 2023-03-30 04:49 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消