Linq查询序列化(WPF,C#,XmlSerializer)

时间:2017-04-14 07:27:39

标签: c# wpf linq serialization xml-serialization

我想序列化我的查询。我做了:

 MyDBViewDataContext db = new MyDBViewDataContext();
 List<test_view> tvq = (from tt in db.test_views
                       select tt).ToList();

 const string filename = "serial_file.xml";

 XmlSerializer serializer = new XmlSerializer(typeof(test_view));
 FileStream stream = new FileStream(filename,FileMode.Create);

 serializer.Serialize(stream, tvq);
 stream.Close();

但是有些错误,因为我收到了错误:

enter image description here

1 个答案:

答案 0 :(得分:1)

更改您的行代码

XmlSerializer serializer = new XmlSerializer(typeof(test_view));

 XmlSerializer serializer = new XmlSerializer(typeof(List<test_view>));