Saving FlowDocument to SQL Server

送分小仙女□ 提交于 2019-12-18 06:48:33

问题


I need to save WPF FlowDocuments to SQL Server. What is the best format for doing that? String? Blob? Does it matter in a document less than 5K words or so?


回答1:


If you just want to store the FlowDocument objects in a database, without any processing, I would recommend using binary serialization, and storing the resulting byte array into a varbinary(max). This is fast and scales well.

However, if you already have the FlowDocuments as XML files, than it would be easier just to dump them into a nvarchar(max) field, with no (added) serialization/deserialization overhead. This scales trivially for values under 8k, and then performs kinda OK until you hit around the 10MB mark.




回答2:


FlowDocument is not serializable so SWeko's answer above will not work. You can use the methods below to get the FlowDocument to and from a Xaml string which can then be saved in the database using nvarchar(max).

    var stringReader = new StringReader(info);
    var xmlTextReader = new XmlTextReader(stringReader);
    return (FlowDocument)XamlReader.Load(xmlTextReader);

and

    var infoString = XamlWriter.Save(info);


来源:https://stackoverflow.com/questions/2447856/saving-flowdocument-to-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!