1

We're trying to serialize some data, and one of the items in a collection is a "deferred execution linq statement" (actually it's the result of a Concat call on a collection).

The problem is how to persist that object. It doesn't support ISerializable. The actual type is something along the lines of System.Linq.Enumerable.WhereSelectListIterator<>

Just wondering if anyone had run into this before, and what the solution was.

4

2 回答 2

2

你可以调用ToList()Linq 语句;这将收集所有结果并将它们返回到List<T>您可以序列化的 a 中。

于 2009-11-04T21:08:25.263 回答
1

如果查询结果并对其进行序列化不是一种选择,您将不得不以某种方式手动序列化查询。

一个问题是有太多不同的 LINQ 查询对象类型。所有这些类型都是框架内部的。这几乎把你锁起来了。

不过,您的具体情况可能有解决方案。如果您需要序列化的唯一查询类型是Concat调用的结果,则解决方案可能不会太复杂。一切都取决于您要连接的集合以及您(或想要)序列化它们的方式。

于 2009-11-04T21:18:20.920 回答