• Home
  • Tutorials
  • API
  • Change Log
  • Github

    Show / Hide Table of Contents
    • Home
    • Attributes
    • Generating SQL
      • Object To Sql
      • DataTable To Sql
      • Readable Sql

    Primary Keys

     var primaryKeys = new DataTable().PrimaryKey; 
     // THESE ARE YOUR PRIMARY KEYS COLUMNS
    

    Identity Fields

    DataColumn column;
    if(column.AutoIncrement){
          // THEN THIS COLUMN WILL BE TREATED AS A IDENITTY FIELD 
    }
    

    Creating SQL

       var actionType = ActionType.Update; // A enum with the values Insert,Update,Delete,Upsert
       var dtToSql = new DataTableToSql(DataBaseType.SqlServer);
       var dt = new DataTable(); //
       var updateSql = dtToSql.BuildQuery(dt,actionType);
       var upsertSql = dtToSql.BuildQuery(dt,ActionType.Upsert);
       var deleteSql = dtToSql.BuildQuery(dt,ActionType.Delete);
    
    Warning

    Executing the a update,upsert, or delete query with a datatable that doesn't have any datacolumn declared as primary key will lead to an InvalidOperationException being thrown.

    Creating DB Parameters From DataRow

    var parameters = dtToSql.BuildDbParameterList(new DataTable().Rows[0] (s, o) => new SqlParameter(s, o));
    

    [Tip] The method BuildDBParameterList has an overload that accepts Func<object, string> to allow for columns to be serialize for those senarios where your storing properties as json,csv or xml

    • Improve this Doc
    Back to top Copyright © 2019 Joseph McNeal Jr