序列化对象并将其存储到数据库中的 varbinary 字段

发布于 2024-07-29 00:53:25 字数 358 浏览 2 评论 0原文

我可以使用以下方法将对象序列化到文件:

var writeStream = File.Open("l.osl", FileMode.Create);
var bformatter = new BinaryFormatter();
bformatter.Serialize(writeStream, l);

我想做的是将其写入 DB varbinary 字段,而不是将其写入文件。 我假设我必须将 writeStream 更改为其他内容,但是什么? 我可以将一个对象放在那里,然后将该对象插入到数据库中吗(我正在使用 LINQ)。

这行得通吗?

PS:我环顾四周,找不到任何可靠的例子。

I can serialize an object to a file using:

var writeStream = File.Open("l.osl", FileMode.Create);
var bformatter = new BinaryFormatter();
bformatter.Serialize(writeStream, l);

What I am trying to do is instead of writing it to a file, write it to a DB varbinary field.
I assume that I have to change writeStream to something else, but what? Can I just put an object in there and there insert that object into the DB (I'm using LINQ).

Will this work?

PS: I have looked around and can't find any solid examples.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文