直接序列化的C#类到SQL Server?

编程入门 行业动态 更新时间:2024-10-21 09:20:20
本文介绍了直接序列化的C#类到SQL Server?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

任何人都可以提出来序列数据的最佳方式(A类实际上)到一个数据库?

can anyone suggest the best way to serialize data (a class actually) to a DB?

我使用SQL Server 2008,但我presume我需要在数据库中存储之前的类将字符串/或其他数据类型的序列化?

I am using SQL server 2008 but i presume i need to serialize the class to a string / or other data type before storing in the database?

我presume此字段必须是文本或二进制??

I presume that this field needs to be text or binary??

请问SQL Server 2008中(或.NET 3.5)支持直接序列tothe数据库??

Does SQL server 2008 (or 3.5) support serializing directly tothe database ??

任何帮助真的AP preciated

Any help really appreciated

推荐答案

您可以XML中的类序列化到XML字段。我们使用一个ETL这一切的时候了异常日志记录。

You can xml serialize the class into an xml field. We use this all the time for exception logging in an ETL.

使用XmlSerializer你可能需要一个辅助方法,其中的某处序列化类的字符串...

Using the XmlSerializer you may want a helper method somewhere which serializes the class to a string...

public static string SerializeToXml<T>(T value) { StringWriter writer = new StringWriter(CultureInfo.InvariantCulture); XmlSerializer serializer = new XmlSerializer(typeof(T)); serializer.Serialize(writer, value); return writer.ToString(); }

然后,只需把字符串转换成像任何其他数据库。

Then just put the string into the db like any other.

更多推荐

直接序列化的C#类到SQL Server?

本文发布于:2023-11-11 18:19:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579212.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序列化   SQL   Server

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!