0

I am fairly new to ASP.NET, and I am trying to develop an application with I guess the database first. I most say the database isn't completed, and I use Microsoft SQL Server to maintain and develop the database. Since it is a new project I am developing my application using MVC 5, and I am able to see the table in Server Exploration, I did this by TOOLS->Connect to database. I am unsure on how to create the models.

Lets say I have a table call HOUSE with the following property

HOUSE
-----
ID        int
Name      nvchar
CreatedOn datetime
UpdatedOn datetime

I am not to sure how to create the model and the controller. Would I create my model as follow

public class House
{
    public int ID { get; set; }
    public string Name { get; set; }
    public Datetime CreatedOn { get; set; }
    public DateTime UpdatedOn { get; set; }
}

Do I need to setup a context or so?

I have followed this tutorial here to allow me to create the connection between Visual Studio and SQL Server, what the next step allow me to create the model.

1 Answer 1

2

You can use Entity FrameWork to directly generate the Model classes from your database, Right click on your project, got to add=> new item. From their select "ADO.net Entity Data Model" under data column. Add that and select "Generate From Database". Using that wizard you can show entity framework the database which you need to work with, so it will automatically generate model classes for you

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.