Displaying database and table creation result at the end

邮差的信 提交于 2019-12-25 08:17:06

问题


I am creating database and tables from c# code so at the end i would like to display result like below:

TableName          Result
Table1             Success
Table2             Success
Table3             Error:Inapproproiate datatype precision for decimal


public class Tables
{
   public string Name { get; set; }
   public List<Column> Columns { get; set; }
}

public class Column
{
    public string Name { get; set; }
    public string Datatype { get; set; }
    public string IsNullable { get; set; }
    public Int32? Size { get; set; }
    public byte? NumericPrecision { get; set; }
    public Int32? NumericScale { get; set; }
}

[HttpPost]
public ActionResult CreateDatabase(string database,List<Tables> tables)
{
   //Here i am thinking to call just method of repository that will create whole database structure for me..
}

public class DatabaseRepo
{
    public void CreateDb(string database,List<Tables> tables)
    {
        var queryList = new List<string>();
        queryList.Add("CREATE DATABASE " + database);

        foreach (var table in tables)
        {
             queryList.Add(CreateTableScript(table.Name, table.Columns)); //This method will create table script for me.
        }
    }
}

Note:I am just considering Datatype,Isnullable,Precision and scale value for insert operation

Now my question is should i execute individual table or i should execute list of all tables at once and most important thing is how do i process this tables by opening a connection 1 time and closing connection after all database and tables are created and display result for each table at the end???

I am thinking of class like below which will return result to my web service:

Public class Result
{
   public string TableName { get; set; }
   public bool Status { get; set; }
   public string ErrorMessage { get; set; }
}

Can anybody please guide me to do this??

来源:https://stackoverflow.com/questions/41118619/displaying-database-and-table-creation-result-at-the-end

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!