I got problem with creating *.cs (C# Class) based on XML generated by serializing another C# class. XSD.exe throws following error:
- A column named 'Conditions' already belongs to this DataTable: cannot set a
nested table name to the same name.
My process looks like this:
- Writing some C# code (example below)
- Serialize to XML use XSD.EXE to
- create *.cs Deserialize to new *.cs
- (for shipping) etc
The classes which are serialized to XML (in point 1) looks like this:
public class A
{
public A(){}
private List<string> _cond = new List<String>();
public List<string> Conditions
{
开发者_如何学编程 get{ return _cond; }
set{ _cond = value }
}
}
public class B:A
{
}
public class C:A
{
}
public class Data
{
B b = new B();
C c = new C();
/* ... ADD SOME DATA etc ... */
}
// After that I serialize to XML the "Data" class object
Can anyone suggest of workaround ?! This is clearly cause by inherided condition property
You can change the way xsd.exe creates the output, n your case, it would make sense to use the /c(lasses) switch. Then, it will not create a dataset but "ordinary" classes instead.
There's also LinqToXsd, which has a fairly decent code generator.
精彩评论