【问题标题】:c# datasource to memory and memory to xml filec#数据源到内存和内存到xml文件
【发布时间】:2025-12-11 15:55:02
【问题描述】:

我有一个要求

  1. 将数据库查询中的数据源保存到内存中,以便循环 通过并更新内存中的一些项目。
  2. 我还需要能够将项目保存在内存中(根据上面第 1 项的结果) 到硬盘上的xml 文件。
  3. 最后我需要能够将xml 文件加载到内存中。

谁能指出最简单的方法。这一切都在 Windows 服务中完成。

FAItemsUnderControl fItemsUnderControl = new FAItemsUnderControl(ConfigurationManager.AppSettings["DatabaseConnectionString"]);

//Note the line below is for binding to a gridview which is incorrect in my requirement but illustrates the idea

GridViewItemsUnderControlReport.DataSource = fItemsUnderControl.getItemsUnderControl("systemidtbd", "ALL");

【问题讨论】:

  • 1. fItemsUnderControl已经在内存中,2和3可以用System.Xml.Serialization
  • 我试图将结果映射到对象列表,但它不起作用。

标签: c# xml database service datasource


【解决方案1】:

我必须在我的服务端声明相同的对象列表

// Get items to Control into running memory
                FAItemsUnderControl fItemsUnderControl = new FAItemsUnderControl(ConfigurationManager.AppSettings["DatabaseConnectionString"]);
                MyGlobals.ListOfItemsToControl = fItemsUnderControl.getItemsUnderControl(MyGlobals.System_ID, "ALL").ToList<Usp_GetListItemsBySystemResult>();

【讨论】: