Click here to Skip to main content
12,895,062 members (43,892 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 8 Jan 2013

How to change database with Entity Code First in ASP.NET MVC3

, 8 Jan 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
A website application with ASP.NET MVC3 for my blog

While implementing a project with Entity Code First, I found out an interesting thing to share. In the project I made a personal blog. Here I create a class that contains the attributes, in this case a Table

I create a class Article with properties, including:

public class Article
    public int ArticleId { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }
    [Column(TypeName = "ntext")]
    public string Content { get; set; }

    private DateTime _datetime = DateTime.Now;
    public DateTime DateTime {
        get { return _datetime; } set { _datetime=value;} 
    public int Hot { get; set; }
    public string AccountId { get; set; }
    public int CategoryId { get; set; }
    public int Active { get; set; }

Next, I create a DbContext for generating class Article into Table Article:

public DbSet<Article> Article { get; set; }

Then, I change in Global for section Application_Start:

protected void Application_Start()


Then press F5 for run project.

Happy coding!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Truong Minh Tuan
Web Developer iFsoft Software Center
Vietnam Vietnam
I am a Developer for ASP/ASP.NET and currently a CEO of a small E-learning company in VietNam. We are very much active in making training videos , writing books and center trainings. Do visit my site for

You may also be interested in...


Comments and Discussions

QuestionDatabase can not change if Model is changed Pin
sanghuynh_re15-Jan-13 17:18
membersanghuynh_re15-Jan-13 17:18 
AnswerRe: Database can not change if Model is changed Pin
Truong Minh Tuan17-Jan-13 20:02
memberTruong Minh Tuan17-Jan-13 20:02 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170424.1 | Last Updated 8 Jan 2013
Article Copyright 2013 by Truong Minh Tuan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid