here is the code only bold parts are changed or added
public class DbTablesContext : DbContext
{
public DbTablesContext(string connectionstring) : base(connectionstring)
{
}
}
public class TableStructure
{
public string TableName { get; set; }
}
public ActionResult Index()
{
List<tablestructure> listOfTable = new List<tablestructure>();
using (
DbTablesContext db = new DbTablesContext(ConnectionString())
)
{
listOfTable = db.Database.SqlQuery<tablestructure>("select name as TableName from sys.tables").ToList();
}
ViewData["data"] = listOfTable;
return View();
</tablestructure></tablestructure></tablestructure>}
public string ConnectionString()
{
SqlConnectionStringBuilder sqlbuild = new SqlConnectionStringBuilder();
sqlbuild.DataSource = "(LocalDB)\\v11.0";
sqlbuild.InitialCatalog = "playDB";
return sqlbuild.ConnectionString;
}
@{
ViewBag.Title = "Index";
}
@{
}
Updated:
you only need to change TableStructure calss in order to be matched with your query result.
look at the query :
select name as TableName from sys.tables
as you see the result in my query is 'TableName' column so i had to create a class with 'TableName' property that was the idea. so You don't need to mention the column names just the result should be matched with your class