在SQL Server表中存储对象 [英] Storing objects in SQL Server table

查看:110
本文介绍了在SQL Server表中存储对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我需要在SQL Server 2000表中存储自定义对象。

这是最简单的方法吗?我是否需要编写方法将每个属性

与C#app分开存储到表中,反之亦然?


问候,


迭戈F.

Hello. I need to store custom objects in a SQL Server 2000 table. Which is
the easiest way to do it? Do I need to write methods to store each attribute
separately from C# app to the table and the opposite as well?

Regards,

Diego F.

推荐答案

我自己没有理由这样做但是你来自ISerializable,并且/>
重写它强制你覆盖的方法(用于序列化)以及
作为一个特殊的构造函数,它接受一个SerializationInfo和其他东西

(用于反序列化) )。通过添加和检索名称 - 值对,您可以选择这两种方法来选择您想要序列化的数据。

在序列化命名空间中,然后是类叫做

''BinaryFormatter'',它接受一系列可序列化的对象,并且
将它们转换为二进制流。

看看在''ISerializable''下的msdn上。

" Diego F." <二***** @ NOterra.es>在消息中写道

新闻:%2 **************** @ TK2MSFTNGP10.phx.gbl ...
Haven''t had cause to do it myself but you derive from ISerializable, and
overrride the method that it forces you to override (for serializing) aswell
as a special constructor which takes a SerializationInfo and something else
(for deserializing). These two methods are where you choose what data you
want to serialize, by adding and retrieving name-value pairs.
In the Serialization namespace, there''s then a class called something like
''BinaryFormatter'' which takes an array of the serializable objects and
converts them to a binary stream.
Look on msdn under ''ISerializable''.
"Diego F." <di*****@NOterra.es> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
你好。我需要在SQL Server 2000表中存储自定义对象。哪个是最简单的方法呢?我是否需要编写方法将每个
属性与C#app分开存储到表中,以及相反的方法?

问候,

Diego F.
Hello. I need to store custom objects in a SQL Server 2000 table. Which is
the easiest way to do it? Do I need to write methods to store each attribute separately from C# app to the table and the opposite as well?

Regards,

Diego F.



但是如果我直接将对象存储为二进制数据,我可以在

表中查询吗?我正在考虑编写方法将属性映射到表格

字段。


问候,


迭戈F.


" Beeeeeves" < beeeeeeeeev @ VES> escribióenel mensaje

news:OU ************** @ TK2MSFTNGP11.phx.gbl ...
But if I store the objects directly as binary data, can I make querys in the
table? I''m thinking of writing methods to map the attributes to table
fields.

Regards,

Diego F.

"Beeeeeves" <beeeeeeeeev@ves> escribió en el mensaje
news:OU**************@TK2MSFTNGP11.phx.gbl...
Haven''t有理由自己做,但你从ISerializable派生,并且
覆盖它强制你覆盖(用于序列化)
的方法,以及一个特殊的构造函数,它接受一个SerializationInfo和
else (用于反序列化)。通过添加和检索名称 - 值对,您可以选择这两种方法来选择要序列化的数据。
在Serialization命名空间中,有一个名为
的类。 ''BinaryFormatter''获取可序列化对象的数组并将它们转换为二进制流。
在''ISerializable''下查看msdn。

" Diego F." <二***** @ NOterra.es>在消息中写道
新闻:%2 **************** @ TK2MSFTNGP10.phx.gbl ...
Haven''t had cause to do it myself but you derive from ISerializable, and
overrride the method that it forces you to override (for serializing) aswell as a special constructor which takes a SerializationInfo and something else (for deserializing). These two methods are where you choose what data you
want to serialize, by adding and retrieving name-value pairs.
In the Serialization namespace, there''s then a class called something like
''BinaryFormatter'' which takes an array of the serializable objects and
converts them to a binary stream.
Look on msdn under ''ISerializable''.
"Diego F." <di*****@NOterra.es> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
你好。我需要在SQL Server 2000表中存储自定义对象。哪个
是最简单的方法呢?我是否需要编写方法将每个
Hello. I need to store custom objects in a SQL Server 2000 table. Which is the easiest way to do it? Do I need to write methods to store each


属性

与C#app分开存储到表中,并且反之亦然?

问候,

迭戈F.
separately from C# app to the table and the opposite as well?

Regards,

Diego F.




我的第一个猜测是,如果你想使用序列化数据用于除了反序列化之外的
,即在反序列化时对它运行查询,

然后你不会使用ISerializable并编写自定义序列化

函数生成序列化数据的格式你将能够b $ b查询。

但是如果研究二进制数据的格式一旦它被序列化,它可以是你可以设计一个查询来实现它。

迭戈F. <二***** @ NOterra.es>在消息中写道

news:uf ************** @ TK2MSFTNGP12.phx.gbl ...
My first guess is that if you want to use the serialized data for purposes
other than deserializing, i.e. run a query on it while it''s deserialized,
then you would not use ISerializable and write a custom serialization
function to produce the serialized data in the format you will be able to
query.
But if you study the format of the binary data once it''s serialized it may
be that you can devise a query to do it.
"Diego F." <di*****@NOterra.es> wrote in message
news:uf**************@TK2MSFTNGP12.phx.gbl...
但是如果我存储了对象直接作为二进制数据,我可以在
表中查询吗?我正在考虑编写方法将属性映射到表格
字段。

问候,

迭戈F.

; Beeeeeves" < beeeeeeeeev @ VES> escribióenel mensaje
新闻:OU ************** @ TK2MSFTNGP11.phx.gbl ...
But if I store the objects directly as binary data, can I make querys in the table? I''m thinking of writing methods to map the attributes to table
fields.

Regards,

Diego F.

"Beeeeeves" <beeeeeeeeev@ves> escribió en el mensaje
news:OU**************@TK2MSFTNGP11.phx.gbl...
Haven没有理由这样做它本身但你从ISerializable派生,并且
覆盖它强制你覆盖(用于序列化)的方法以及
Haven''t had cause to do it myself but you derive from ISerializable, and
overrride the method that it forces you to override (for serializing) aswell
作为一个特殊的构造函数,它接受一个SerializationInfo和
as a special constructor which takes a SerializationInfo and something


else


else

(用于反序列化)。这两种方法是你选择什么数据
(for deserializing). These two methods are where you choose what data you
想要序列化,通过添加和检索名称 - 值对。
在序列化中命名空间,然后有一个名为
的类,如''BinaryFormatter'',它接受一系列可序列化的对象,并将它们转换为二进制流。
查看msdn下的' 'ISerializable''。

" Diego F." <二***** @ NOterra.es>在消息中写道
新闻:%2 **************** @ TK2MSFTNGP10.phx.gbl ...
want to serialize, by adding and retrieving name-value pairs.
In the Serialization namespace, there''s then a class called something like ''BinaryFormatter'' which takes an array of the serializable objects and
converts them to a binary stream.
Look on msdn under ''ISerializable''.
"Diego F." <di*****@NOterra.es> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
你好。我需要在SQL Server 2000表中存储自定义对象。
Hello. I need to store custom objects in a SQL Server 2000 table.



哪种方法最简单?我是否需要编写方法将每个


Which is the easiest way to do it? Do I need to write methods to store each


属性

与C#app分开存储到表中,并且反之亦然?

问候,

迭戈F.
separately from C# app to the table and the opposite as well?

Regards,

Diego F.





这篇关于在SQL Server表中存储对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆