Unable to create new TableSchema in BigQuery with C#

474 views Asked by At

I am trying to create Google BigQuery Table Schema Explicitly, TableSchema.Fields.Add() method throws Object Reference Exception.

        TableSchema Schema = response.Schema;

        TableFieldSchema sc1 = new TableFieldSchema();
        sc1.Name = "CustomerID";
        sc1.Type = "STRING";
        sc1.Mode = "NULLABLE";

        Schema.Fields.Add(sc1); -- Throws Error.
1

There are 1 answers

0
selva kumar On BEST ANSWER

I can able to create new TableSchema in .NET client library by using below code.

TableSchema Schema = new TableSchema();
TableFieldSchema F1 = new TableFieldSchema();
F1.Name = "COLUMN NAME";
F1.Type = "STRING";
F1.Mode = "REQUIRED";

TableFieldSchema F2 = new TableFieldSchema();
F1.Name = "COLUMN NAME";
F1.Type = "INTEGER";
F1.Mode = "NULLABLE";

//Add N number of fields as per your needs

System.Collections.Generic.IList<TableFieldSchema> FS = new System.Collections.Generic.List<TableFieldSchema>();
FS.Add(F1);
FS.Add(F2);

Schema.Fields = FS;