/// <summary>
        /// Gets the list of tables for the current dbcontext.
        /// </summary>
        /// <returns>IReadOnlyCollection&lt;DatasetInfo&gt;.</returns>
        public IReadOnlyCollection <DatasetInfo> GetDatasets()
        {
            var entityTypes = DbContext.Model.GetEntityTypes();
            var tables      = new List <DatasetInfo>(entityTypes.Count());

            foreach (var entityType in entityTypes)
            {
                var tableName  = entityType.GetTableName();
                var schemaName = entityType.GetSchema();

                var dataset = new DatasetInfo(tableName, schemaName);

                foreach (var property in entityType.GetProperties())
                {
                    var name = property.GetColumnName();
                    var type = property.ClrType;
                    var isPK = property.IsPrimaryKey();

                    dataset.AddColumn(new ColumnInfo(name, type, isPK));
                }

                tables.Add(dataset);
            }

            return(tables.AsReadOnly());
        }
Exemple #2
0
        /// <summary>
        /// Reads the schema.
        /// </summary>
        /// <exception cref="DatasetImporterException">
        /// Wrong file format at {_jsonReader.LineNumber}:{_jsonReader.LinePosition}
        /// or
        /// Wrong file format. No 'columns' property in 'schema'
        /// </exception>
        protected virtual void ReadSchema()
        {
            if (_jsonReader.TokenType != JsonToken.StartObject)
            {
                throw new DatasetImporterException($"Wrong file format at {_jsonReader.LineNumber}:{_jsonReader.LinePosition}");
            }

            if (ReadToProperty("columns"))
            {
                _jsonReader.Read();
                if (_jsonReader.TokenType != JsonToken.StartArray)
                {
                    throw new DatasetImporterException($"Wrong file format at {_jsonReader.LineNumber}:{_jsonReader.LinePosition}");
                }

                while (_jsonReader.Read() &&
                       _jsonReader.TokenType != JsonToken.EndArray)
                {
                    if (_jsonReader.TokenType != JsonToken.StartObject)
                    {
                        throw new DatasetImporterException($"Wrong file format at {_jsonReader.LineNumber}:{_jsonReader.LinePosition}");
                    }

                    string name = null;
                    string type = null;

                    while (_jsonReader.Read() &&
                           _jsonReader.TokenType != JsonToken.EndObject)
                    {
                        var propName = _jsonReader.Value.ToString();
                        if (propName == "name")
                        {
                            name = _jsonReader.ReadAsString();
                        }
                        else if (propName == "type")
                        {
                            type = _jsonReader.ReadAsString();
                        }
                        else
                        {
                            _jsonReader.Skip();
                        }
                    }

                    _datasetInfo.AddColumn(new ColumnInfo(name, type));
                }

                _jsonReader.Read();
            }
            else
            {
                throw new DatasetImporterException($"Wrong file format. No 'columns' property in 'schema'");
            }
        }
 /// <summary>
 /// Reads the dataset schema.
 /// </summary>
 protected virtual void ReadSchema()
 {
     if (ReadToElement("Columns"))
     {
         while (_xmlReader.Read() &&
                _xmlReader.NodeType != XmlNodeType.EndElement)
         {
             if (_xmlReader.NodeType == XmlNodeType.Element)
             {
                 _datasetInfo.AddColumn(new ColumnInfo(_xmlReader.GetAttribute("name"), _xmlReader.GetAttribute("type")));
             }
         }
     }
 }