Back to
Latest changes:

This is an old revision of the document!

Building data model dynamically by information from DataTable

DataModel class has a special method FillByDataTable() which you can use to add a table, an entity and its attributes into your data model by some DataTable object. You can call it several times to add more tables and entities. After that you will possibly need to add links between tables.

Here is an example which adds into data model all default operators, two tables (Customers and Orders), corresponding entities and a link between those tables:

    //clear current model
    //add default operators
    //create necessary DataTable objects (here we suppose connection is an instance of some DbConnection descendant type)
    DataSet tempDS = new DataSet();
    OleDbDataAdapter custDA = new OleDbDataAdapter("SELECT * FROM CUSTOMERS", DbConnection);
    custDA.Fill(tempDS, "Customers");
    DataTable custTable = tempDS.Tables["Customers"];
    //add Customer table into data model. Correponding entity is also created (second parameter is true)
    model.FillByDataTable(custTable, true);
    OleDbDataAdapter ordDA = new OleDbDataAdapter("SELECT * FROM ORDERS", DbConnection);
    ordDA.Fill(tempDS, "Orders");
    DataTable ordTable = tempDS.Tables["Orders"];
    //add Orders table into data model.
    model.FillByDataTable(ordTable, true);
    //After that we need to add links between those tables:
    TableLink newLink = new TableLink();
    newLink.Table1 = model.Tables.FindByAlias("Customer");
    newLink.Table2 = model.Tables.FindByAlias("Orders");
    newLink.Type = TableLink.LinkType.Inner;
    TableLink.Condition newCond = new TableLink.Condition(newLink);
    newCond.Expr1 = "CustNo";
    newCond.Expr2 = "CustNo";
    newCond.Operator = "=";


, 2014/09/25 00:19
How can I execute the query and retrive the information ?
, 2014/11/03 08:58
Download our trial version. It contains several examples of using EasyQuery for information retrieval.
Enter your comment: