How to store User defined data type through DataContext?
I used DataContractSerializer to save user data but now I want to use DataContext for my database design. But the system existed struture as below cannot b开发者_运维知识库e stored through DataContext.
class Data
{
public DataType1;
public DataType2;
}
It seems these APIs cannot support storing user defined data type. I don't want to separate all data members because this system uses these structure every where. If I changed the structure, it is hard to maintain and the DataType1 contains a List<> member. I don't know how to do even though separating this structure.
Could you please kindly to give me some suggestions? Thanks.
It seems these APIs cannot support storing user defined data type
If that were true the api would be completely without purpose.
The DataContractSerializer
has what appear to be conflicting rules in an attempt to make serialisation more implicit. You can for example serialise a public type that has public properties and a public default constructor without having to decorate it with a DataContract
attribute or any of its members with a DataMember
attribute.
Looks to me that at the very least you need make Data
a public class. Most likely you would need to review your other classes to ensure that either they are implicitly serializable or that you explictly mark them up with the DataContract
and DataMember
attributes.
Dear all: But now I used DataContext
DataContext cannot serialize the user defined type even marked [Serializable].
The workaround seems to separate all the members into one class now.....
Thanks.
精彩评论