5
Answers

How to get records by passing multiple column names in MVC5

Seshu B

Seshu B

7y
461
1
Hi all..
by passing single column name binding records but i want to get records by passing multiple column names dynamically using entity framework.
please provide soultion regarding this 
 
I have tried like this...
 
public List<string> GetRecords(List<string> Columns,string tablename)
{
using (var Context = new MCPEntities())
{
string columnnames = string.Join(",", Columns);
string Query = "SELECT " + columnnames + " FROM " + tablename + " ";
var Records = Context.Database.SqlQuery<string>(Query).ToList();
return Records.ToList();
}
Answers (5)
2
Ravi Patel

Ravi Patel

NA 7.8k 532.4k 8y
Hi,
I hope you are talking about code first approach
once you create database using code first approach then after that if you want to change the model class . that reflect your database
if you do not want loose any column value then use migration
here is step
open your package manager console type the following comand
1. enable-migrations
2. add-migration
3. update-database
when ever you change the model class repeat the second and third step
 
for more details  check this
 
http://www.c-sharpcorner.com/UploadFile/4b0136/perform-code-first-migration-in-Asp-Net-mvc-5/ 
0
Bikesh Srivastava

Bikesh Srivastava

NA 19.8k 835k 8y
I think you are saying about Migration.
Visit here:-
http://www.dotnet-tricks.com/Tutorial/entityframework/R54K181213-Understanding-Entity-Framework-Code-First-Migrations.html