Fill dataset with MongoDB and c #

0

How can I migrate this Oracle code to MongoDB? I'm using C # and the idea is to fill the Dataset with Mongo data.

  

Original Code

    private DataSet datos()
    {
        DataSet dataSet;
        OracleCommand oracleCommand = conn.CreateCommand();
        DataSet dataSet1 = new DataSet("empDataSet");
        try
        {
            OracleDataAdapter oracleDataAdapter = new OracleDataAdapter();
             conn.Open();

            oracleCommand.CommandText = "SELECT * from table";
            oracleDataAdapter.set_SelectCommand(oracleCommand);
            oracleDataAdapter.Fill(dataSet1, "EmployeesData2");
            oracleCommand.Dispose();
            oracleDataAdapter.Dispose();
            return dataSet1;
        }
        catch (Exception exception1)
        { dataSet = null;       }
        return dataSet;
    }
  

My Advances:

 protected static IMongoClient clienteLocal = new MongoClient();
  protected static IMongoDatabase dataLocal = clienteLocal.GetDatabase("database");
  var tabla = dataLocal.GetCollection<BsonDocument>("tabla");
            var filtro = Builders<BsonDocument>.Filter.Empty;
            var cursor = tabla.Find(filtro);
            var listado = cursor.ToList();
            foreach (var item in listado)
            {                    
             //Se sopone que ya esta listo el query para mostrar todos los datos existentes, pero como se llena el data?' o existe alguna manera equivalente
            }
    
asked by Rastalovely 24.01.2017 в 01:07
source

1 answer

0

If you have an entity you can convert it to datatable with the help of CopyToDataTable

Creating a DataTable From a Query (LINQ to DataSet)

Analyze the section "Creating a Custom CopyToDataTable Method" you will see that it is simple to use

    
answered by 25.01.2017 в 03:30