views:

82

answers:

1

I'm using System.Data.Design.TypedDataSetGenerator to convert a .xsd file (generated by VS2008) into a strongly-typed DataSet class compatible with .NET 2.0. From what I understand from MSDN, the HierarchicalUpdate option must be specified to get the same result that the VS2008 IDE generates:

HierarchicalUpdate - Generates typed datasets that have a TableAdapterManager and associated methods for enabling hierarchical update.

So I've specified that option, as you can see in the code below, but the outputted .Designer.cs file contains no TableAdapterManager... it doesn't even have any TableAdapters! Does VS2008 have its own internal Typed DataSet generator that it uses, or am I missing something, or is this a .NET bug?

  string schemaContent;

  using (StreamReader reader = new StreamReader(@"C:\CVS\CallRetrieverPlain\CallRetrieverPlain\CallRecordingsDataSet.xsd"))
  {
    schemaContent = reader.ReadToEnd();
  }

  string output = string.Empty;

  using (CSharpCodeProvider cscp = new CSharpCodeProvider())
  {
    CodeCompileUnit ccu = new CodeCompileUnit();
    CodeNamespace cn = new CodeNamespace("DataSet.Generation.Test");

    output = TypedDataSetGenerator.Generate(schemaContent, ccu, cn, cscp,
                                            TypedDataSetGenerator.GenerateOption.HierarchicalUpdate);

    using (StringWriter codeWriter = new StringWriter())
    {
      // *** this line causes full generation as expected ***
      cscp.GenerateCodeFromNamespace(cn, codeWriter, null);
      cscp.GenerateCodeFromCompileUnit(ccu, codeWriter, null);

      output = codeWriter.ToString();
    }
  }

  using (StreamWriter writer = new StreamWriter(@"C:\test-tmp\CallRecordingsDataSet.Designer.cs"))
  {
    writer.Write(output);
  }

EDIT: played around a bit more and found I have to add a call to CodeDomProvider.GenerateCodeFromNamespace() as well as CodeDomProvider.GenerateCodeFromCompileUnit() (commented in the above code). It works perfectly now!

A: 

Solved it myself, see the comments in the question.

Ian Kemp