Hi,
How do you make a class generated by the DataSet.xsd serializable? So I can store it in session with SQL Server?
Thanks.
You can mark the class as serilizable like this:
[Serializable]
public class MyClass
{
//Class code...
}
Thanks. But the class I am trying to Serialized is generated by DataSet.xsd, so I cannot do that.
I have tried to make a partial class but it does not work:
[Serializable]
public partial class DataSetXSDClassName {
}
OH! Sorry... I missed the part of the xsd... Can you post the class generated by it then?
I am not sure about that but you can do the followin work around.
Provided your generated class look like this:
public class A{public int id;public string titlepublic A(int aId,string aTitle) { id = aId; title = aTitle; }}//then you define class B like this:[Serializable]public class B{public int id;public string title;public B(A obj) { id = obj.id; title = obj.title; }}after that you can serialize and deserialize instances of B class and then use their members/properties to create A object and further use it in your code. Other benefit of it is that you can serialize only the information that you need.
The class is not actually 'physical' that I can go and copy and paste the code, but if any error occur then it will show up in debug mode, but will a weird filename like like random string.
Also the 'work around' class does work, but that will generated a class 99% the same as the one from xsd file. Any changes in dataset.xsd means I manually have to do the same for this 'work around' class.
But thanks for the comment.
0 comments:
Post a Comment