2017-04-14 68 views
0

我想序列化我的查詢。我所做的:Linq查詢serializaton(WPF,C#,XmlSerializer)

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

更改您的代碼行

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

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

謝謝* * ** TRIV!剛剛測試,它的工作:) – 4est

+0

很高興它有幫助... – TriV