It depends what you mean by "serialization" (it is an overloaded term). If you mean your existing object as columns, then and ORM: EF, LINQ-to-SQL, NHibernate, etc. If you mean your object as a single varbinary(max)
/ varchar(max)
:
Whatever else you do, don't use BinaryFormatter
- this will break if you change the fields (for example, changing a regular property into an auto-property). You need something contract-based, most of which will be fine with changes. Suggestions:
XmlSerializer
/ DataContractSerializer
/ Json.NET (text)
- protobuf-net (binary, uses google's "protocol buffers" wire format)
With the above you can generally use pretty standard DTOs; for example (compatible with DataContractSerializer
and protobuf-net):
[DataContract]
public class Customer {
[DataMember(Order=1)]
public int {get;set;}
[DataMember(Order=2)]
public string Name {get;set;}
}
I wouldn't use NetDataContractSerializer
for similar reasons to BinaryFormatter
- fine for short-lived requests, but not good for storage. Note that most serializers use concrete classes, since very few include the type metadata in the output (and hence would need additional configuration to tie ICustomer
to your Customer
class).