在 SQL 数据库中读取和写入 .NET 对象,无需序列化

发布于 2024-10-11 12:07:03 字数 311 浏览 1 评论 0原文

我有一个小疑问。我需要创建自己的缓存服务,用于向数据库写入和读取 .NET 对象。现在,我在二进制序列化的帮助下实现了这一目标。但问题是我需要故意将我的对象标记为 [Serialized],这让我想到如果有人尝试添加一个未标记为 [Serialized] 的对象该怎么办。

因此,我需要找到一种无需序列化即可将对象读写到数据库的方法。

我也有一个想法..众所周知,Session 可以在其中存储任何对象。现在,我们可以将会话存储在数据库outproc中。它使用什么机制来存储这些对象而不需要序列化或反序列化。

任何帮助将不胜感激。

谢谢。 MB

I have a small query. I need to create a Caching Service of my own that will write and read .NET Objects to and from the Database. Now, I have achieved that with the help of Binary Serialization. But the Problem is I need to deliberately marked my objects as [Serializable], which makes me think that what if someone will try to add an object which is not marked as [Serializable].

Thus, I need to find a way to read and write Objects to Database without Serialization.

I have one thought too.. As we all know Session can store any object in it. Now, we can make sessions to be stored in the DB, outproc. What mechanism it uses to store these objects without serializing or deserializing.

Any help will be highly appreciated.

Thanks.
M.B

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瀟灑尐姊 2024-10-18 12:07:03

如果它以任何方式保存到磁盘,它就会以某种方式序列化状态。您可以轻松地自行使用 XML 序列化到数据库。

查看 System.Xml.Serialization 命名空间。

If it's saving to disk in any manner, it is serializing the state in some manner. You can easily serialize with XML to the database on your own.

Check out the System.Xml.Serialization namespace.

血之狂魔 2024-10-18 12:07:03

序列化对象意味着从该对象获取信息并以标准方式将其存储到某种形式的永久存储中,以便以后可以通过该信息有效地重建该对象。任何要写入数据库的对象都应该是可序列化的。如果在没有某种形式的序列化过程的情况下存储它,那么当尝试反序列化时,该对象可能会以奇怪或不一致的状态读回。

To serialize an object means to take the information from that object and store it to some form of permanent store in a standard way so that the object can later be effectively reconstructed via that information. Any object which is going to be written out to a database should be serializable. If it is being stored without some form of serialization process, then when deserialization is attempted the object may possibly be read back in a strange or inconsistent state.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文