Click here to Skip to main content
15,892,005 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: visitors tag printing. Pin
forest4ever12-Jun-16 23:30
forest4ever12-Jun-16 23:30 
QuestionDynamically change grid.mvc in partial view in MVC? Pin
dshilpa8-Jun-16 19:43
dshilpa8-Jun-16 19:43 
AnswerRe: Dynamically change grid.mvc in partial view in MVC? Pin
Richard MacCutchan8-Jun-16 20:59
mveRichard MacCutchan8-Jun-16 20:59 
GeneralRe: Dynamically change grid.mvc in partial view in MVC? Pin
dshilpa8-Jun-16 22:30
dshilpa8-Jun-16 22:30 
AnswerRe: Dynamically change grid.mvc in partial view in MVC? Pin
John C Rayan8-Jun-16 22:55
professionalJohn C Rayan8-Jun-16 22:55 
QuestionPost ifram embedded PDF editable document to ASP.Net MVC Post Action Pin
Asjad ali kash8-Jun-16 1:01
Asjad ali kash8-Jun-16 1:01 
Questionsorting of a image column Pin
mrakshay12127-Jun-16 23:56
mrakshay12127-Jun-16 23:56 
QuestionTrying to create database using Code First Approach Pin
indian1437-Jun-16 16:20
indian1437-Jun-16 16:20 
Hi All,

I am trying to write a Code First Approach which is using Entity Framework and Web Api. When I run the application first time its not creating a new database instead giving me the following error.
The model backing the 'MVCDBContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
Here is my Controller
namespace MVCWithWebApiApp.Controllers
{
    public class UserController : Controller
    {
        public ActionResult Index()
        {
            var dbContext = new MVCDBContext();

            List<User> listOfEmployees;
            //var a = oDAL.employees;
            listOfEmployees = dbContext.Users.ToList();
            return Json(listOfEmployees, JsonRequestBehavior.AllowGet);

            //return View();
        }

        //
        // GET: /User/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /User/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /User/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /User/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /User/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /User/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /User/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}

And here is my Db Context
namespace MVCWithWebApiApp.Models
{
    public class MVCDBContext : DbContext
    {
        public DbSet<User> Users { get; set; }
    }
}

And here is my Model
namespace MVCWithWebApiApp.Models
{
    public class User
    {
        private int _userId;
        public int UserId
        {
            get { return _userId; }
            set { _userId = value; }
        }

        private string _userName;
        public string UserName
        {
            get { return _userName; }
            set { _userName = value; }
        }

    }
}
When I am trying to call the as "" "[^]

Then it is hitting the break point in the Action method "public ActionResult Index()"

But giving me the error as I mentioned above
My Connection string in Web Config is:
<add name="MVCDBContext" providerName="System.Data.SqlClient" connectionString="Data Source=KNW-DEL-ABDUL\SQL2008R2;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"/>

Please help me how to generate a database on the back-end using Code First approach.

And I have another question since I am new to Code First Approach, how can I update changes on the database without losing already existing data. Means I am thinking in Code First once the database is created then how can implement new schema changes etc on database without effecting the existing data? Do I need to drop the whole Database again and recreate it and then do data migration. Isn't that difficult. And that too when I run my application for several times is it going to create database those many of times?

These are also my questions. But the above 1st question is very important as I am not able to create the database itself first.

Thanks in advance.
Thanks,

Abdul Aleem

"There is already enough hatred in the world lets spread love, compassion and affection."

Rant[REPOST] Trying to create database using Code First Approach Pin
Richard Deeming8-Jun-16 1:41
mveRichard Deeming8-Jun-16 1:41 
AnswerRe: Trying to create database using Code First Approach Pin
jkirkerx10-Jun-16 7:56
professionaljkirkerx10-Jun-16 7:56 
QuestionWhat is Diffrent between hash table and dictionary Pin
jitendra jayswal7-Jun-16 1:26
jitendra jayswal7-Jun-16 1:26 
SuggestionRe: What is Diffrent between hash table and dictionary Pin
Richard MacCutchan7-Jun-16 3:23
mveRichard MacCutchan7-Jun-16 3:23 
QuestionUsing Webgrease, Best Practices, vs Gulp and Bower Pin
jkirkerx5-Jun-16 12:26
professionaljkirkerx5-Jun-16 12:26 
AnswerI decided to dump Webgrease and the bundle, and use Gulp, bower, git and node to automate the task. Pin
jkirkerx6-Jun-16 9:19
professionaljkirkerx6-Jun-16 9:19 
QuestionGoogle map with multiple marked location Pin
Member 118050633-Jun-16 3:38
Member 118050633-Jun-16 3:38 
AnswerRe: Google map with multiple marked location Pin
ZurdoDev3-Jun-16 4:40
professionalZurdoDev3-Jun-16 4:40 
QuestionHttpWebRequest authentication problem Pin
candogu2-Jun-16 3:07
candogu2-Jun-16 3:07 
AnswerRe: HttpWebRequest authentication problem Pin
ZurdoDev2-Jun-16 3:14
professionalZurdoDev2-Jun-16 3:14 
GeneralRe: HttpWebRequest authentication problem Pin
candogu2-Jun-16 3:16
candogu2-Jun-16 3:16 
GeneralRe: HttpWebRequest authentication problem Pin
ZurdoDev2-Jun-16 3:19
professionalZurdoDev2-Jun-16 3:19 
AnswerRe: HttpWebRequest authentication problem Pin
John C Rayan2-Jun-16 3:18
professionalJohn C Rayan2-Jun-16 3:18 
AnswerRe: HttpWebRequest authentication problem Pin
F-ES Sitecore2-Jun-16 4:24
professionalF-ES Sitecore2-Jun-16 4:24 
QuestionAsp.Net MVC View, Loading HTML in iframe element instead of src=url Pin
jkirkerx1-Jun-16 11:25
professionaljkirkerx1-Jun-16 11:25 
AnswerRe: Asp.Net MVC View, Loading HTML in iframe element instead of src=url Pin
Richard Deeming2-Jun-16 2:21
mveRichard Deeming2-Jun-16 2:21 
GeneralRe: Asp.Net MVC View, Loading HTML in iframe element instead of src=url Pin
jkirkerx2-Jun-16 6:36
professionaljkirkerx2-Jun-16 6:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.