首页> 外文期刊>Windows Developer Magazine >Mapping SQL Data to Class Properties
【24h】

Mapping SQL Data to Class Properties

机译:将SQL数据映射到类属性

获取原文
获取原文并翻译 | 示例
       

摘要

AS DISCUSSED IN LAST month's column, the XML serialization process generates an XML representation of the data stored in a. NET Framework class. Only the public fields of the class are taken into account and the whole process aborts if the class holds circular references with other managed classes. The Xml Seri al izer class is the. NET Framework tool that governs the process. You use this class to serialize a living instance of a class to a persistence medium and to recreate an object from a source. Last month, I briefly hinted at a bunch of events. You can take advantage of them during the deserialization step whenever the input stream contains an XML document that doesn't match the schema of the object being deserialized. The programmer can fix things up and programmatically map the unmatched XML node to a particular combination of fields in the target object using events such as UnknownNode. This technique is often used to deserialize across different versions of the class. For example, Version 1.0 of the application saves a class. Next, Version 2.0 of the application that manages a slightly different version of the class needs to deserialize the bytes. Using this approach, the same data can be easily mapped to new, or simply renamed, fields. Taken to the limit, the feature also proves useful in a more enticing scenario―mapping SQL Server data directly to class instances. In this article, I'll show how to execute a query that returns XML data and map the various nodes to fields of a predefined class. The process should not be read simply as the deserialization of an instance of the same class. More exactly, the technique discussed here represents a way to map, in total or in part, any XML document stored in a database to any class usable within a. NET application.
机译:正如在上个月的专栏中讨论的那样,XML序列化过程生成存储在a中的数据的XML表示形式。 NET Framework类。如果该类拥有与其他托管类的循环引用,则仅考虑该类的公共字段,并且整个过程将中止。 Xml Seri alizer类是。 NET Framework工具来管理该过程。您可以使用此类将类的活动实例序列化为持久性介质,并从源重新创建对象。上个月,我简短地暗示了一系列事件。每当输入流包含与正在反序列化的对象的模式不匹配的XML文档时,就可以在反序列化步骤中利用它们。程序员可以解决问题,并使用诸如UnknownNode之类的事件以编程方式将不匹配的XML节点映射到目标对象中字段的特定组合。该技术通常用于在类的不同版本之间反序列化。例如,应用程序的1.0版保存一个类。接下来,管理类的版本稍有不同的应用程序的版本2.0需要反序列化字节。使用这种方法,可以将相同的数据轻松地映射到新的或简单地重命名的字段。达到极限,该功能还被证明在更诱人的方案中很有用-将SQL Server数据直接映射到类实例。在本文中,我将展示如何执行查询以返回XML数据并将各种节点映射到预定义类的字段。该过程不应简单地理解为对同一类实例的反序列化。更确切地说,此处讨论的技术代表了一种将全部或部分存储在数据库中的XML文档全部映射到a中可用的任何类的方法。 NET应用程序。

著录项

相似文献

  • 外文文献
  • 中文文献
  • 专利
获取原文

客服邮箱:kefu@zhangqiaokeyan.com

京公网安备:11010802029741号 ICP备案号:京ICP备15016152号-6 六维联合信息科技 (北京) 有限公司©版权所有
  • 客服微信

  • 服务号