在 SQL 数据库中读取和写入 .NET 对象,无需序列化
我有一个小疑问。我需要创建自己的缓存服务,用于向数据库写入和读取 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果它以任何方式保存到磁盘,它就会以某种方式序列化状态。您可以轻松地自行使用 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.
序列化对象意味着从该对象获取信息并以标准方式将其存储到某种形式的永久存储中,以便以后可以通过该信息有效地重建该对象。任何要写入数据库的对象都应该是可序列化的。如果在没有某种形式的序列化过程的情况下存储它,那么当尝试反序列化时,该对象可能会以奇怪或不一致的状态读回。
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.