Volleyball Scoring (vii)--using the EF framework, creating a controller, building a database

Source: Internet
Author: User
Tags connectionstrings

Before we use the EF framework, we need to write the model classes well. Then create the controller.

In the previous blog, we have designed, and completed the model class, at this time

We just need to get the code here and we can use it.

Balls.cs

Namespace Volleyball scoring program. Models
{
public class Ball
{
public int ID {get; set;}
public string xingming {get; set;}
public string Age {get; set;}
public string Weizhi {get; set;}
public string Shenglv {get; set;}
public string Rongyu {get; set;}

}
public class Balldbcontext:dbcontext
{
Public dbset<ball> Movies {get; set;}

}
}

AnnounceInfo.cs

Namespace Volleyball team announcement information. Models.entities
{
public class Announceinfo
{
public int ID {get; set;}
public string Title {get; set;}
public string Content {get; set;}
public string duiming {get; set;}
public string Jieshao {get; set;}
public int Category {get; set;}
}
}

CategoryInfo.cs

Namespace Volleyball team announcement information. Models.entities
{
public class CategoryInfo
{

public string Name {get; set;}

public int ID {get; set;}
}
}

Team.cs

Namespace volleyball scoring. Models
{
public class Team
{
public int ID {get; set;} ID number
public string Name {get; set;} Team Name
Public decimal score {get; set;} Score

public string Team {get; set;}
public string score {get; set;}
public string Add {get; set;}
public string Delete {get; set;}
public string Faqiu {get; set;}
public string Lanwang {get; set;}
public string Kouqiu {get; set;}
public string Zhugong {get; set;}

}

}

After the model class is created, you need to add a link string to the Web. config file:

<connectionStrings>
<add name= "Balldbcontext"
Connectionstring= "Data source= (LocalDB) \v11.0; attachdbfilename=| datadirectory|\balls.mdf;integrated Security=true "
Providername= "System.Data.SqlClient"

/>
<add name= "defaultconnection" connectionstring= "Data source= (LocalDb) \v11.0;initial catalog= Aspnet-Volleyball scoring procedure -20170617163815;integrated Security=sspi; attachdbfilename=| Datadirectory|\aspnet-Volleyball Scoring Program -20170617163815.mdf "providername=" System.Data.SqlClient "/>
</connectionStrings>

Then access the data model from the controller:
· Controller name Input: Ballscontroller.

· Model class Selection: Balls (Volleyball scoring procedure). Models).

· Data Context class Selection: Ballsdbcontext (Volleyball scoring procedure). Models)
· Create create.cshtml, delete.cshtml, details.cshtml, edit.cshtml, and index.cshtml files in the new Views\movies folder.

Visual Studio automatically creates crud (create, read, update, and Delete) action methods, and related view files (crud Auto-created action methods and view files are called scaffolding). Now you have all the Web features you can create, list, edit, and delete volleyball players.

Run the application to browse the movies controller by appending the/balls to the URL of the browser address bar. Because the application relies on the default route (as defined in the App_start\routeconfig.cs file), the browser request Http://localhost:xxxxx/Movies is routed to the balls controller's default index action method. In other words, browser request Http://localhost:xxxxx/Balls is equivalent to browser request Http://localhost:xxxxx/Movies/Index.

We can see the files generated by the system for us. Then we can do the work on these files;

Clicking "Show All Files" on the solution will show the database generated from the model:

Here we use the EF framework, complete the model class, then create the controller, connect the database, and access it.

In the case of the EF framework, the database connection is very convenient and easy to use.

Volleyball Scoring (vii)--using the EF framework, creating a controller, building a database

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.