PDA

View Full Version : how to save an object to database



Silverboy
یک شنبه 28 فروردین 1384, 09:16 صبح
سلام خواستم بدونم که چه جور یک شیی (object) رو با asp.net توی یک Database مثلا
sql server میشه ذخیره کرد ؟ :oops:

md_bluelily
یک شنبه 28 فروردین 1384, 09:45 صبح
فکر میکنم باید اون Object رو Serialize کنید بعد داخل یک فیلد، با توجه به متد Serialization مورد استفادتون، ذخیرش کنید.

:موفق:

titbasoft
یک شنبه 28 فروردین 1384, 10:34 صبح
البته این خبر خوب رو هم بدم که در sql server 2005 شما به راحتی میتونید یک فیلد رو از نوع یک کلاس بگیرید. :reading:

Silverboy
یک شنبه 28 فروردین 1384, 11:09 صبح
می شه یکمی بیشتر توضیح بدید

M.GhanaatPisheh
یک شنبه 28 فروردین 1384, 11:27 صبح
زمر سوال کلمه شما در Serialize و Deserialize کردن داده هاست.
توی MSDN جستجو کنید.


Serialization is the process of converting the state of an object into a form that can be persisted or transported. The complement of serialization is deserialization, which converts a stream into an object. Together, these processes allow data to be easily stored and transferred.

The .NET Framework features two serializing technologies:

Binary serialization preserves type fidelity, which is useful for preserving the state of an object between different invocations of an application. For example, you can share an object between different applications by serializing it to the Clipboard. You can serialize an object to a stream, to a disk, to memory, over the network, and so forth. Remoting uses serialization to pass objects "by value" from one computer or application domain to another.
XML serialization serializes only public properties and fields and does not preserve type fidelity. This is useful when you want to provide or consume data without restricting the application that uses the data. Because XML is an open standard, it is an attractive choice for sharing data across the Web. SOAP is likewise an open standard, which makes it an attractive choice.



‌Binary :

Serialization can be defined as the process of storing the state of an object to a storage medium. During this process, the public and private fields of the object and the name of the class, including the assembly containing the class, are converted to a stream of bytes, which is then written to a data stream. When the object is subsequently deserialized, an exact clone of the original object is created.


When implementing a serialization mechanism in an object-oriented environment, you have to make a number of tradeoffs between ease of use and flexibility. The process can be automated to a large extent, provided you are given sufficient control over the process. For example, situations may arise where simple binary serialization is not sufficient, or there might be a specific reason to decide which fields in a class need to be serialized. The following sections examine the robust serialization mechanism provided with the .NET Framework and highlight a number of important features that allow you to customize the process to meet your needs.


XML and SOAP Serialization :


XML serialization converts (serializes) the public fields and properties of an object, or the parameters and return values of methods, into an XML stream that conforms to a specific XML Schema definition language (XSD) document. XML serialization results in strongly typed classes with public properties and fields that are converted to a serial format (in this case, XML) for storage or transport.

Because XML is an open standard, the XML stream can be processed by any application, as needed, regardless of platform. For example, XML Web services created using ASP.NET use the XmlSerializer class to create XML streams that pass data between XML Web service applications throughout the Internet or on intranets. Conversely, deserialization takes such an XML stream and reconstructs the object.

XML serialization can also be used to serialize objects into XML streams that conform to the SOAP specification. SOAP is a protocol based on XML, designed specifically to transport procedure calls using XML.

To serialize or deserialize objects, use the XmlSerializer class. To create the classes to be serialized, use the XML Schema Definition tool