Chuyển tới nội dung
Home » Mvc 5 Entity Framework | Conventions

Mvc 5 Entity Framework | Conventions

ASP.NET MVC 5 - Bài 8: Kết nối với cơ sở dữ liệu bằng Entity framework - Đơn giản, dễ sử dụng

Các thành phần chính của Entiy model

– Class cấu hình kết nối

– Các class ánh xạ cho Table và kết quả trả về của store

– Chuỗi kết nối trong file config

4. Cách cập nhật Entity model

Để cập nhật các thay đổi từ trong database, chúng ta thao tác theo các bước sau:

Bước 1: Mở mô hình kết nối của Model entity. Click đúp chuột vào File model

Bước 2: Tại giao diên mô hình liên kết bảng, phải chuột chọn Update model from database

Bước 3. Thêm các bảng hoặc store mới tạo tab Add . Cập nhật thay đổi mở tab Refress . Nhấn Finish để hoàn tất. Nhấn Ctrl + S để lưu lại Model

Back to: ASP.NET MVC Tutorial For Beginners and Professionals

@ViewBag.title


https://hoanguyenit.com

@foreach (var user in ViewBag.users) {

}

@user.Username @user.Password @{ if (user.Lever == 1) {

Admin

} else {

Member

} }

Demo:

Okay, vậy là xong rồi ::)

ASP.NET MVC 5 - Bài 8: Kết nối với cơ sở dữ liệu bằng Entity framework - Đơn giản, dễ sử dụng
ASP.NET MVC 5 – Bài 8: Kết nối với cơ sở dữ liệu bằng Entity framework – Đơn giản, dễ sử dụng

Tạo models trong Asp.net MVC 5

Hình bên trên mình tạo một table Users nên mình sẽ xây đựng mô hình thực thể cho User như sau:Click Models->add class User.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace MVC5_HelloWorld.Models { public class User { [Key, Column(Order = 1)] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int idUser { get; set; } public string Username { get; set; } public string Password { get; set; } public int Lever { get; set; } } }

Entity Framework in ASP.NET MVC

In this article, I am going to discuss how to use Entity Framework in ASP.NET MVC Application to interact with SQL Server Database to perform the CRUD operation. In the ASP.NET MVC application, the controller responds to the incoming HTTP request, then gets the data from a model and hands it over to the view. The view then renders the data. The model can be entities or business objects. Here, in this article, we are going to discuss how to retrieve the data from the SQL Server Database using the Entity Framework Database First Approach in ASP.NET MVC Application. In our upcoming article, we will discuss using business objects as our model.

Creating the Database with Required Table and Data:

Please use below SQL Script to create the MVC_DB Database, Employee table and populate the Employee table with test data:

–Create a database called MVC_DB CREATE DATABASE MVC_DB GO –Use MVC_DB USE MVC_DB GO –Create a Table called Employee CREATE TABLE Employee ( EmployeeId int Primary Key Identity(1,1), Name nvarchar(50), Gender nvarchar(10), City nvarchar(50), Salary decimal(18,2) ) GO –Insert some values into Employee Table INSERT INTO Employee values(‘Pranaya’,’Male’,’Mumbai’, 2000) INSERT INTO Employee values(‘Sambit’,’Male’,’Chennai’, 3000) INSERT INTO Employee values(‘Priyanka’,’Female’,’Hydrabad’, 4000) INSERT INTO Employee values(‘Anurag’,’Male’,’Cheenai’, 4000) INSERT INTO Employee values(‘Subrat’,’Male’,’Mumbai’, 3000) INSERT INTO Employee values(‘Preety’,’Female’,’Mumbai’, 2000) INSERT INTO Employee values(‘Trupti’,’Female’,’Hyderabad’, 5000) GO

Let us understand how to use Entity Framework in ASP.NET MVC Application step by step.

Step1: Create a new Empty ASP.NET MVC Application

Open Visual Studio and click on the New Project link on the Startup page as shown below. Alternatively, you can also select the File menu -> New Project option from the Context menu.

From the New Project window as shown in the below image, expand the Visual C# node and select Web from the left pane. From the middle pane select ASP.NET Web Application. Provide a meaningful name to your project such as CRUD_OperationsInMVC. Select the location where you want to create the project by clicking on the Browse button. Finally, click on the OK button as shown in the below image.

Once you click on the OK button a new dialog will pop up for selecting project Templates as shown in the below image. From the below window, we are going to choose the Empty Project Template and Select MVC from Add Folders and core reference section.

You can also change the authentication by clicking on the Change Authentication button. You can select the appropriate authentication mode for your application. Here, we are not going to have any authentication for our application. So select the No Authentication radio button and click OK. (By default, Individual User Accounts would be selected to authenticate users stored in the SQL Server database.)

Wait for some time till Visual Studio creates a simple MVC project using the default template.

Step2: Adding ADO.NET Entity Data Model in ASP.NET MVC Application

Right-Click on Models Folder, and then select Add => New Item from the context menu which will open the Add New Item window. From the “Add New Item” window, from the left pane expand Installed => Visual C# => Data option. From the middle pane select the ADO.NET Entity Data Model template. Provide a meaningful name to your data model such as EmployeeDataModel and finally click on the Add button as shown in the below image.

From the next Entity Data Model Wizard screen, as we are going to use the Entity Framework Database First approach, so select EF Designer from Database option and click on the Next button as shown in the image below.

In the next step, click on the new connection From Choose your data connection wizard as shown below.

Provide the necessary details to communicate with the database such as Server name, select the Authentication Type, select the Database and click on the Ok button as shown below.

Then provide a meaningful name for the connection string that is going to save in the web.config file. Here, I am naming the connection string as EmployeeDBContext and then click on the Next button as shown in the below image.

Select the version of Entity Framework

Here I am going to use Entity Framework 6.x, so I am selecting the Entity Framework 6.x radio button and click on the Next button as shown in the below image.

Selecting the Database Objects

Then we need to select the database object for our application. As our database has one table, so we need to select that Employee Table. Provide a meaningful namespace to your EDMX file and finally click on the Finish button as shown in the below image.

Once you click on the Finish button, let’s see what the things are created by Entity Framework. It will add the reference to the Entity Framework in the reference folder.

The framework will create the EDMX file within the Models folder.

It will create the Employee Model.

To see the Employee Model click on Employee.cs file, this is inside the EmployeeDataModel.tt File

namespace CRUD_OperationsInMVC.Models { using System; using System.Collections.Generic; public partial class Employee { public int EmployeeId { get; set; } public string Name { get; set; } public string Gender { get; set; } public string City { get; set; } public Nullable

Salary { get; set; } } }

It will create the connection string in the web.config file as shown below.

It will create the DBContext class for us whose name is the same as the name of the connection string that is EmployeeDBContext. The EmployeeDBContext class derives from the DbContext class and is responsible for establishing a connection to the database. The EmployeeDataModel.Context.cs which is inside EmployeedataModel.Context.tt as sown below.

Below is the auto-generated code for the EmployeeDBContext class

namespace CRUD_OperationsInMVC.Models { using System; using System.Data.Entity; using System.Data.Entity.Infrastructure; public partial class EmployeeDBContext : DbContext { public EmployeeDBContext() : base(“name=EmployeeDBContext”) { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { throw new UnintentionalCodeFirstException(); } public virtual DbSet

Employees { get; set; } } }

That’s it. We successfully created our Entity Data Model. Now it’s time to use this model in our application.

Creating Controller:

Right-Click on Controllers Folder. Select Add => Controller => Select MVC5 Controller Empty and then click on add button as shown in the below image.

In the next Screen provide the controller name as EmployeeController and click on the Add button as shown below.

Let’s modify the default route in the RouteConfig class so that when the application runs for the first time it will redirect to the Index Action method of Employee Controller.

After modifying the RouteConfig class the codes looks like as shown below

namespace CRUD_OperationsInMVC { public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”); routes.MapRoute( name: “Default”, url: “{controller}/{action}/{id}”, defaults: new { controller = “Employee”, action = “Index”, id = UrlParameter.Optional } ); } } }

Let’s modify the index action method of employee controller to use entity framework as shown below

namespace CRUD_OperationsInMVC.Controllers { public class EmployeeController : Controller { public ActionResult Index() { EmployeeDBContext dbContext = new EmployeeDBContext(); List

empList = dbContext.Employees.ToList(); return View(empList); } } }

Let’s create the index view.

Right-click on the Index Action Method and click on Add View. Then paste the following code in the Index,cshtml file.

@model IEnumerable

@foreach (var item in Model) {

}

@Html.DisplayNameFor(model => model.Name) @Html.DisplayNameFor(model => model.Gender) @Html.DisplayNameFor(model => model.City) @Html.DisplayNameFor(model => model.Salary)
@Html.DisplayFor(modelItem => item.Name) @Html.DisplayFor(modelItem => item.Gender) @Html.DisplayFor(modelItem => item.City) @Html.DisplayFor(modelItem => item.Salary)

That’s it. Now run the application and you should get the result as expected as shown in the below image.

Here, in this article, we just see how to use Entity Framework in ASP.NET MVC Application. In our upcoming articles, we will discuss how to perform CRUD operations in ASP.NET MVC using Entity Framework with a real-time example. In the next article, I am going to discuss how to create Hyperlink in ASP.NET MVC application.

About the Author: Pranaya Rout

Pranaya Rout has published more than 3,000 articles in his 11-year career. Pranaya Rout has very good experience with Microsoft Technologies, Including C#, VB, ASP.NET MVC, ASP.NET Web API, EF, EF Core, ADO.NET, LINQ, SQL Server, MYSQL, Oracle, ASP.NET Core, Cloud Computing, Microservices, Design Patterns and still learning new technologies.

Tiếp tục với các bài viết trước, nay mình chia sẻ với mọi người, mình dùng DBContext để Connect Database trong ASP.NET MVC5. Bạn có thể xem lại các bài viết trước dưới đây:

  • ASP.NET MVC 5 Hello World
  • ASP.NET MVC 5 Create Shared Layout Razor & ViewStart
  • ASP.NET MVC 5 Install Bootstrap

Ok, để tạo connect được database trong ASP.NET MVC5, ta có thể connect SQL SERVER hoặc tạo database trong project luôn. Nhưng trước hết ta cần sự hổ trợ của EntityFramework, trong project này mình sẽ install EntityFramework 6.x. Bạn nhớ vào Manage Nuget Packages gõ EntityFramework để cài đặt nó

Entity Framewok : nói sơ sơ là nó giúp ta ánh xạ các đối tượng quan hệ trong CSDL được dùng trong ADO.NET.

Tạo bằng cách thủ công như hình sau: click chuột file App_Data->tạo một database, sao đó tạo table

Mình sẽ chỉ mọi người các tạo thủ công này, để xử lý một cách tùy ý. Sau khi tạo xong để connnect được tên Database vừa tạo bạn copy câu lệnh chuỗi sao dán vào project/Web.config

Bạn nhớ khai báo biến name và tên database để ta cấu hình connect

C# MVC CRUD Tutorial | Asp.net MVC Full CRUD Operation Using Entity Framework | Simplilearn
C# MVC CRUD Tutorial | Asp.net MVC Full CRUD Operation Using Entity Framework | Simplilearn

Initialize DB with test data

Entity Framework can automatically create (or drop and re-create) a database for you when the application runs. You can specify that this should be done every time your application runs or only when the model is out of sync with the existing database. You can also write a

Seed

method that Entity Framework automatically calls after creating the database in order to populate it with test data.

The default behavior is to create a database only if it doesn’t exist (and throw an exception if the model has changed and the database already exists). In this section, you’ll specify that the database should be dropped and re-created whenever the model changes. Dropping the database causes the loss of all your data. This is generally okay during development, because the

Seed

method will run when the database is re-created and will re-create your test data. But in production you generally don’t want to lose all your data every time you need to change the database schema. Later you’ll see how to handle model changes by using Code First Migrations to change the database schema instead of dropping and re-creating the database.

  1. In the DAL folder, create a new class file named SchoolInitializer.cs and replace the template code with the following code, which causes a database to be created when needed and loads test data into the new database.


    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.Entity; using ContosoUniversity.Models; namespace ContosoUniversity.DAL { public class SchoolInitializer : System.Data.Entity. DropCreateDatabaseIfModelChanges

    { protected override void Seed(SchoolContext context) { var students = new List

    { new Student{FirstMidName="Carson",LastName="Alexander",EnrollmentDate=DateTime.Parse("2005-09-01")}, new Student{FirstMidName="Meredith",LastName="Alonso",EnrollmentDate=DateTime.Parse("2002-09-01")}, new Student{FirstMidName="Arturo",LastName="Anand",EnrollmentDate=DateTime.Parse("2003-09-01")}, new Student{FirstMidName="Gytis",LastName="Barzdukas",EnrollmentDate=DateTime.Parse("2002-09-01")}, new Student{FirstMidName="Yan",LastName="Li",EnrollmentDate=DateTime.Parse("2002-09-01")}, new Student{FirstMidName="Peggy",LastName="Justice",EnrollmentDate=DateTime.Parse("2001-09-01")}, new Student{FirstMidName="Laura",LastName="Norman",EnrollmentDate=DateTime.Parse("2003-09-01")}, new Student{FirstMidName="Nino",LastName="Olivetto",EnrollmentDate=DateTime.Parse("2005-09-01")} }; students.ForEach(s => context.Students.Add(s)); context.SaveChanges(); var courses = new List

    { new Course{CourseID=1050,Title="Chemistry",Credits=3,}, new Course{CourseID=4022,Title="Microeconomics",Credits=3,}, new Course{CourseID=4041,Title="Macroeconomics",Credits=3,}, new Course{CourseID=1045,Title="Calculus",Credits=4,}, new Course{CourseID=3141,Title="Trigonometry",Credits=4,}, new Course{CourseID=2021,Title="Composition",Credits=3,}, new Course{CourseID=2042,Title="Literature",Credits=4,} }; courses.ForEach(s => context.Courses.Add(s)); context.SaveChanges(); var enrollments = new List

    { new Enrollment{StudentID=1,CourseID=1050,Grade=Grade.A}, new Enrollment{StudentID=1,CourseID=4022,Grade=Grade.C}, new Enrollment{StudentID=1,CourseID=4041,Grade=Grade.B}, new Enrollment{StudentID=2,CourseID=1045,Grade=Grade.B}, new Enrollment{StudentID=2,CourseID=3141,Grade=Grade.F}, new Enrollment{StudentID=2,CourseID=2021,Grade=Grade.F}, new Enrollment{StudentID=3,CourseID=1050}, new Enrollment{StudentID=4,CourseID=1050,}, new Enrollment{StudentID=4,CourseID=4022,Grade=Grade.F}, new Enrollment{StudentID=5,CourseID=4041,Grade=Grade.C}, new Enrollment{StudentID=6,CourseID=1045}, new Enrollment{StudentID=7,CourseID=3141,Grade=Grade.A}, }; enrollments.ForEach(s => context.Enrollments.Add(s)); context.SaveChanges(); } } }




    The


    Seed

    method takes the database context object as an input parameter, and the code in the method uses that object to add new entities to the database. For each entity type, the code creates a collection of new entities, adds them to the appropriate

    DbSet

    property, and then saves the changes to the database. It isn’t necessary to call the

    SaveChanges

    method after each group of entities, as is done here, but doing that helps you locate the source of a problem if an exception occurs while the code is writing to the database.

  2. To tell Entity Framework to use your initializer class, add an element to the


    entityFramework

    element in the application Web.config file (the one in the root project folder), as shown in the following example:

    The


    context type

    specifies the fully qualified context class name and the assembly it’s in, and the

    databaseinitializer type

    specifies the fully qualified name of the initializer class and the assembly it’s in. (When you don’t want EF to use the initializer, you can set an attribute on the

    context

    element:

    disableDatabaseInitialization="true"

    .) For more information, see Configuration File Settings.

    An alternative to setting the initializer in the Web.config file is to do it in code by adding a


    Database.SetInitializer

    statement to the

    Application_Start

    method in the Global.asax.cs file. For more information, see Understanding Database Initializers in Entity Framework Code First.

The application is now set up so that when you access the database for the first time in a given run of the application, Entity Framework compares the database to the model (your

SchoolContext

and entity classes). If there’s a difference, the application drops and re-creates the database.

Note

When you deploy an application to a production web server, you must remove or disable code that drops and re-creates the database. You’ll do that in a later tutorial in this series.

Tạo class connect đến Database kế thừa từ DBContext.

DBContext được dùng trong Entity Framework là một phần rất quan trọng để ta có thể kết nối được với các thực thể table trong CSDL của ta, nói cách khác dùng để connect database xong, sao đó ta có thể (insert, update,delete,query).

Models/demoEntities.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using MVC5_HelloWorld.Models; using System.Data.Entity; using System.Data.Entity.ModelConfiguration.Conventions; namespace MVC5_HelloWorld.Models { public class demoEntities : DbContext { public demoEntities() : base(“demoASPEntities”) { } public DbSet

Users { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity

().ToTable(“Users”); modelBuilder.Conventions.Remove (); base.OnModelCreating(modelBuilder); } } }

base(“demoASPEntities”): dùng khai báo tên CSDL name connect của taDbSet

Users: Ta dùng khai báo table UsersmodelBuilder.Entity

().ToTable(“Users”): bạn dùng để ánh xạ tới table nào đó trong CSDL của bạn, chẳng hạn bạn dùng ánh xạ tới table UserInfo trong CSDL cũng được nhéVD: modelBuilder.Entity

().ToTable(“UserInfo”)


Để sử dụng được class demoEntities.cs ta vừa tạo, để connect database và thực hiện các câu lệnh (insert, delete,update,query) ta sử dụng như sau:Vào Controllers/HomeController.cs mở file lên chỉnh sửa lại như sau:

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using MVC5_HelloWorld.Models; namespace MVC5_HelloWorld.Controllers { public class HomeController : Controller { private demoEntities _db = new demoEntities(); // GET: Home public ActionResult Index() { var data = (from s in _db.Users select s).ToList(); ViewBag.users = data; ViewBag.title = “MVC5 – Hello World”; return View(); } } }

Views/Home/Index.cshtml chỉnh sửa như code bên dưới

@model MVC5_HelloWorld.Models.User

Tự học ASP.NET MVC 5 - Bài 3 - Làm việc với database bằng Entity Framework Code First
Tự học ASP.NET MVC 5 – Bài 3 – Làm việc với database bằng Entity Framework Code First

Conventions

The amount of code you had to write in order for Entity Framework to be able to create a complete database for you is minimal because of conventions, or assumptions that Entity Framework makes. Some of them have already been noted or were used without your being aware of them:

  • The pluralized forms of entity class names are used as table names.
  • Entity property names are used for column names.
  • Entity properties that are named

    ID

    or classname

    ID

    are recognized as primary key properties.
  • A property is interpreted as a foreign key property if it’s named
    (for example,

    StudentID

    for the

    Student

    navigation property since the

    Student

    entity’s primary key is

    ID

    ). Foreign key properties can also be named the same simply (for example,

    EnrollmentID

    since the

    Enrollment

    entity’s primary key is

    EnrollmentID

    ).

You’ve seen that conventions can be overridden. For example, you specified that table names shouldn’t be pluralized, and you’ll see later how to explicitly mark a property as a foreign key property.

Create the data model

Next you’ll create entity classes for the Contoso University application. You’ll start with the following three entities:

Course <-> Enrollment <-> Student

Entities Relationship
Course to Enrollment One-to-many
Student to Enrollment One-to-many

There’s a one-to-many relationship between

Student

and

Enrollment

entities, and there’s a one-to-many relationship between

Course

and

Enrollment

entities. In other words, a student can be enrolled in any number of courses, and a course can have any number of students enrolled in it.

In the following sections, you’ll create a class for each one of these entities.

Note

If you try to compile the project before you finish creating all of these entity classes, you’ll get compiler errors.

The Student entity

  • In the Models folder, create a class file named Student.cs by right-clicking on the folder in Solution Explorer and choosing Add > Class. Replace the template code with the following code:


    using System; using System.Collections.Generic; namespace ContosoUniversity.Models { public class Student { public int ID { get; set; } public string LastName { get; set; } public string FirstMidName { get; set; } public DateTime EnrollmentDate { get; set; } public virtual ICollection

    Enrollments { get; set; } } }

The

ID

property will become the primary key column of the database table that corresponds to this class. By default, Entity Framework interprets a property that’s named

ID

or classname

ID

as the primary key.

The

Enrollments

property is a navigation property. Navigation properties hold other entities that are related to this entity. In this case, the

Enrollments

property of a

Student

entity will hold all of the

Enrollment

entities that are related to that

Student

entity. In other words, if a given

Student

row in the database has two related

Enrollment

rows (rows that contain that student’s primary key value in their

StudentID

foreign key column), that

Student

entity’s

Enrollments

navigation property will contain those two

Enrollment

entities.

Navigation properties are typically defined as

virtual

so that they can take advantage of certain Entity Framework functionality such as lazy loading. (Lazy loading will be explained later, in the Reading Related Data tutorial later in this series.)

If a navigation property can hold multiple entities (as in many-to-many or one-to-many relationships), its type must be a list in which entries can be added, deleted, and updated, such as

ICollection

.

The Enrollment entity

  • In the Models folder, create Enrollment.cs and replace the existing code with the following code:


    namespace ContosoUniversity.Models { public enum Grade { A, B, C, D, F } public class Enrollment { public int EnrollmentID { get; set; } public int CourseID { get; set; } public int StudentID { get; set; } public Grade? Grade { get; set; } public virtual Course Course { get; set; } public virtual Student Student { get; set; } } }

The

EnrollmentID

property will be the primary key; this entity uses the classname

ID

pattern instead of

ID

by itself as you saw in the

Student

entity. Ordinarily you would choose one pattern and use it throughout your data model. Here, the variation illustrates that you can use either pattern. In a later tutorial, you’ll see how using

ID

without

classname

makes it easier to implement inheritance in the data model.

The

Grade

property is an enum. The question mark after the

Grade

type declaration indicates that the

Grade

property is nullable. A grade that’s null is different from a zero grade — null means a grade isn’t known or hasn’t been assigned yet.

The

StudentID

property is a foreign key, and the corresponding navigation property is

Student

. An

Enrollment

entity is associated with one

Student

entity, so the property can only hold a single

Student

entity (unlike the

Student.Enrollments

navigation property you saw earlier, which can hold multiple

Enrollment

entities).

The

CourseID

property is a foreign key, and the corresponding navigation property is

Course

. An

Enrollment

entity is associated with one

Course

entity.

Entity Framework interprets a property as a foreign key property if it’s named
(for example,

StudentID

for the

Student

navigation property since the

Student

entity’s primary key is

ID

). Foreign key properties can also be named the same simply (for example,

CourseID

since the

Course

entity’s primary key is

CourseID

).

The Course entity

  • In the Models folder, create Course.cs, replacing the template code with the following code:


    using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; namespace ContosoUniversity.Models { public class Course { [DatabaseGenerated(DatabaseGeneratedOption.None)] public int CourseID { get; set; } public string Title { get; set; } public int Credits { get; set; } public virtual ICollection

    Enrollments { get; set; } } }

The

Enrollments

property is a navigation property. A

Course

entity can be related to any number of

Enrollment

entities.

We’ll say more about the DatabaseGeneratedAttribute attribute in a later tutorial in this series. Basically, this attribute lets you enter the primary key for the course rather than having the database generate it.

ASP.Net MVC 5 Database First with Entity Framework 6
ASP.Net MVC 5 Database First with Entity Framework 6

Các bước kết nối cơ sở dữ liệu bằng Entity Framework

Bước 1: Phải chuột và thư mục model, chọn Add -> Chọn New Item. Trong mục Data, chọn ADO.NET Entity data model. Nhấn nút Add đế qua bước tiếp theo

Bước 2: Chọn EF Designer from database để phần mềm tự động tạo các class entity cần thiết. Nhấn next để tiếp tục

Bước 3: Chọn New connection để liên kết tới cơ sở dữ liệu

– Điền thông tin kết nối:

+ Server name: Điền ip máy chủ Database

+ Username: Điền tên đăng nhập của tài khoản truy cấp Database

+ Password: Điền Mật khẩu của tài khoản truy cấp Database

+ Chọn select or enter a database name: Lựa chọn Tên database cần kết nối

=> Nhấn OK để tiếp tục

– Điền thêm lựa chọn tại cửa sổ kết nối: Tích chọn vào mục Yes đế đồng ý thêm chuỗi kết nối vào file Config.

Bước 4: Chọn phiên bản Entity frame work: Chúng ta chọn phiên bản 6x

Bước 5: Lựa chọn các table, store để tạo tự động các class entity ánh xạ tương ứng. Nhấn finish để hoàn thành

Bước 6: Xem mô hình kết quả sau khi kết nối thành công

Install Entity Framework 6

  1. From the Tools menu, choose NuGet Package Manager, and then choose Package Manager Console.

  2. In the Package Manager Console window, enter the following command:


    Install-Package EntityFramework

This step is one of a few steps that this tutorial has you do manually, but that could have been done automatically by the ASP.NET MVC scaffolding feature. You’re doing them manually so that you can see the steps required to use Entity Framework (EF). You’ll use scaffolding later to create the MVC controller and views. An alternative is to let scaffolding automatically install the EF NuGet package, create the database context class, and create the connection string. When you’re ready to do it that way, all you have to do is skip those steps and scaffold your MVC controller after you create your entity classes.

Cổ phiếu top 2 mai tăng: VGS, TLH, DIG, DXG Cảnh giá vùng 1200 | Nhận định thị trường chứng khoán
Cổ phiếu top 2 mai tăng: VGS, TLH, DIG, DXG Cảnh giá vùng 1200 | Nhận định thị trường chứng khoán

Next steps

In this tutorial, you:

  • Created an MVC web app
  • Set up the site style
  • Installed Entity Framework 6
  • Created the data model
  • Created the database context
  • Initialized DB with test data
  • Set up EF 6 to use LocalDB
  • Created controller and views
  • Viewed the database

Advance to the next article to learn how to review and customize the create, read, update, delete (CRUD) code in your controllers and views.

Create the database context

The main class that coordinates Entity Framework functionality for a given data model is the database context class. You create this class by deriving from the System.Data.Entity.DbContext class. In your code, you specify which entities are included in the data model. You can also customize certain Entity Framework behavior. In this project, the class is named

SchoolContext

.

  • To create a folder in the ContosoUniversity project, right-click the project in Solution Explorer and click Add, and then click New Folder. Name the new folder DAL (for Data Access Layer). In that folder, create a new class file named SchoolContext.cs, and replace the template code with the following code:


    using ContosoUniversity.Models; using System.Data.Entity; using System.Data.Entity.ModelConfiguration.Conventions; namespace ContosoUniversity.DAL { public class SchoolContext : DbContext { public SchoolContext() : base("SchoolContext") { } public DbSet

    Students { get; set; } public DbSet

    Enrollments { get; set; } public DbSet

    Courses { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove (); } } }



Specify entity sets

This code creates a DbSet property for each entity set. In Entity Framework terminology, an entity set typically corresponds to a database table, and an entity corresponds to a row in the table.

Note

You can omit the

DbSet

and

DbSet

statements and it would work the same. Entity Framework would include them implicitly because the

Student

entity references the

Enrollment

entity and the

Enrollment

entity references the

Course

entity.

Specify the connection string

The name of the connection string (which you’ll add to the Web.config file later) is passed in to the constructor.


public SchoolContext() : base("SchoolContext") { }

You could also pass in the connection string itself instead of the name of one that is stored in the Web.config file. For more information about options for specifying the database to use, see Connection strings and models.

If you don’t specify a connection string or the name of one explicitly, Entity Framework assumes that the connection string name is the same as the class name. The default connection string name in this example would then be

SchoolContext

, the same as what you’re specifying explicitly.

Specify singular table names

The

modelBuilder.Conventions.Remove

statement in the OnModelCreating method prevents table names from being pluralized. If you didn’t do this, the generated tables in the database would be named

Students

,

Courses

, and

Enrollments

. Instead, the table names will be

Student

,

Course

, and

Enrollment

. Developers disagree about whether table names should be pluralized or not. This tutorial uses the singular form, but the important point is that you can select whichever form you prefer by including or omitting this line of code.

Nhận định thị trường chứng khoán hàng ngày | Phân tích vnindex, cổ phiếu tiềm năng hôm nay
Nhận định thị trường chứng khoán hàng ngày | Phân tích vnindex, cổ phiếu tiềm năng hôm nay

Tutorial: Get Started with Entity Framework 6 Code First using MVC 5

Note

For new development, we recommend ASP.NET Core Razor Pages over ASP.NET MVC controllers and views. For a tutorial series similar to this one using Razor Pages, see Tutorial: Get started with Razor Pages in ASP.NET Core. The new tutorial:

  • Is easier to follow.
  • Provides more EF Core best practices.
  • Uses more efficient queries.
  • Is more current with the latest API.
  • Covers more features.
  • Is the preferred approach for new application development.

In this series of tutorials, you learn how to build an ASP.NET MVC 5 application that uses Entity Framework 6 for data access. This tutorial uses the Code First workflow. For information about how to choose between Code First, Database First, and Model First, see Create a model.

This tutorial series explains how to build the Contoso University sample application. The sample application is a simple university website. With it, you can view and update student, course, and instructor information. Here are two of the screens you create:

In this tutorial, you:

  • Create an MVC web app
  • Set up the site style
  • Install Entity Framework 6
  • Create the data model
  • Create the database context
  • Initialize DB with test data
  • Set up EF 6 to use LocalDB
  • Create controller and views
  • View the database

Create an MVC web app

  1. Open Visual Studio and create a C# web project using the ASP.NET Web Application (.NET Framework) template. Name the project ContosoUniversity and select OK.

  2. In New ASP.NET Web Application – ContosoUniversity, select MVC.

    Note

    By default, the Authentication option is set to No Authentication. For this tutorial, the web app doesn’t require users to sign in. Also, it doesn’t restrict access based on who’s signed in.

  3. Select OK to create the project.

Entity Framework - Relationships: One-to-One, Many-to-Many, One-to-Many
Entity Framework – Relationships: One-to-One, Many-to-Many, One-to-Many

View the database

When you ran the Students page and the application tried to access the database, EF discovered that there was no database and created one. EF then ran the seed method to populate the database with data.

You can use either Server Explorer or SQL Server Object Explorer (SSOX) to view the database in Visual Studio. For this tutorial, you’ll use Server Explorer.

  1. Close the browser.

  2. In Server Explorer, expand Data Connections (you may need to select the refresh button first), expand School Context (ContosoUniversity), and then expand Tables to see the tables in your new database.

  3. Right-click the Student table and click Show Table Data to see the columns that were created and the rows that were inserted into the table.

  4. Close the Server Explorer connection.

The ContosoUniversity1.mdf and .ldf database files are in the %USERPROFILE% folder.

Because you’re using the

DropCreateDatabaseIfModelChanges

initializer, you could now make a change to the

Student

class, run the application again, and the database would automatically be re-created to match your change. For example, if you add an

EmailAddress

property to the

Student

class, run the Students page again, and then look at the table again, you’ll see a new

EmailAddress

column.

Feedback

Submit and view feedback for

Series ASP.NET MVC – Part 2: Tạo ứng dụng web với Entity Framework 6 Code First MVC 5

Bài đăng này đã không được cập nhật trong 5 năm

Giới thiệu bài viết

Ở bài này mình sẽ hướng dẫn các bạn làm ứng dụng web CRUD (Create, Read, Update, Delete) quản lý sản phẩm đơn giản.

Kiến thức của bài

  • Sử dụng Entity Framework 6 code first MVC5 database sử dụng SQL Server 2014.
  • Data Migration
  • Sử dụng ViewModel để hiển thị thông tin.

Cần chuẩn bị

  1. Visual Studio 2013 trở lên.
  2. SQL Server 2012 trở lên.
  3. Entity Framework (EntityFramework NuGet package).
  4. .NET 4.5 trở lên.

Tạo ứng dụng Web

  • Mở Visual Studio (ở đây mình sử dụng VS 2017) và tạo mới ứng dụng đặt tên là ProductManagement.
  • Tiếp theo màn hình hiển thị lên hộp thoại chọn loại Web Application bạn chọn MVC và chọn OK để tiếp tục
  • Đợi để VS tạo project.

Cài đặt package Entity Framework 6

Có 2 cách để bạn cài đặt 1 package:

  1. Sử dụng Manage NutGet Packages.**

    • Trên thanh toolbars của VS bạn chọn Tools => NutGet Package Manager => Manage NutGet Packages for Solution…
    • Tiếp theo ở màn hình Manage NutGet Packages, ở tab Installed quản lý tất cả những packages đã cài cho project của bạn.
    • Sau đó bạn chuyển qua tab Browse để tìm package Entity Framework cần cài cho project. Ở phần này bạn cần chú ý những cái sau: Version của Entity Framework bạn muốn cài ở đây mình chọn version 6.0.0 và thứ hai là project bạn muốn cài (nên để ý cái này vì sau này trong trường hợp Solution của bạn có nhiều project khác nhau). Sau đó bạn chọn Install để tiến hành cài đặt. Trong trường hợp bạn đã cài nhưng do sai version hoặc lỗi gì đó bạn có thể Uninstall trên đây luôn.
    • Trên cửa sổ output của VS sẽ hiển thị ra đợi đến khi thông báo cài đặt thành công là được.
    • Bạn muốn kiểm tra đã thực sự cài thành công vào đúng project của mình thì mở cửa sổ Solution Explorer ra để kiểm tra, nếu đã cài thành công thì trong References của project sẽ có gói Entity Framework trong đó.
  2. Trên thanh toolbars của VS bạn chọn Tools => NutGet Package Manager => Manage NutGet Packages for Solution…

2. Sử dụng Package manager console.

  • Trên thanh toolbars của VS bạn chọn Tools => NutGet Package Manager => Package Manager Console.
  • Sau đó VS sẽ hiển thị ra cửa sổ Package Manager Console. Bạn nhập

    Install-Package EntityFramework

    để tiến hành cài đặt Entity Framework cho project.
  • Ở đây mặc định sẽ cài Entity Framework version mới nhất là 6.2.0 nếu bạn muốn cài version 6.0.0 thì bạn sử dụng

    Install-Package EntityFramework -v 6.0.0

    . Và đợi đến khi thông báo cài đặt thành công là được.

Tạo model

Phân tích qua một chút ở đây mình sẽ tạo 2 model đó là model Product và model CategoryOfProduct. Trong Product là model thể hiển thông tin sản phẩm sẽ có các thuộc tính sau: ProductID, NameOfProduct, CategoryOfProductID. CategoryOfProduct model thể hiện thông tin loại sản phẩm sẽ có các thuộc tính sau: CategoryOfProductID, Description. Quan hệ giữa Product và CategoryOfProduct là quan hệ 1 – n tức là 1 CategoryOfProduct có nhiều Product vì vậy phải đặt khóa chính của CategoryOfProduct làm khóa ngoại cho Product. Mô tả bằng hình ảnh dưới đây:

Trong thư mục Models tạo class Product.cs, bạn có thể theo dõi code dưới đây:


using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace ProductManagement.Models { public class Product { public int ProductID { get; set; } public string NameOfProduct { get; set; } public int CategoryOfProductID { get; set; } } }

Cũng trong thư mục Models bạn tạo tiếp class CategoryOfProduct.cs, bạn có thể theo dõi code dưới đây:


using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace ProductManagement.Models { public class CategoryOfProduct { public int CategoryOfProductID { get; set; } public string Description { get; set; } } }

Kết nối với SQL Server bằng Visual Studio

  • Trên thanh toolbars của VS bạn vào View => Server Explorer.
  • Sau đó trên cửa sổ Server Explorer bạn chọn vào icon mình đã khoanh đỏ để tạo mới connection đến SQL Server.
  • Trên cửa sổ Add Connect, bạn chọn Server Name của SQL Server với login bạn có thể sử dụng login với Window Authentication hoặc login với tài khoản trên SQL Server của bạn. Để kiểm tra xem kết nối của bạn có đúng chưa bằng Test Connection nếu thông báo thành công thì chọn OK để tiếp tục.
  • Trên cửa sổ Server Explorer bạn chuột phải vào Server SQL vừa kết nối chọn New Query. Thêm đoạn code này vào để tạo mới database trong SQL Server

    CREATE DATABASE ProductManagement

    . Chọn nút chạy query để tạo database.

Tạo lớp DatabaseContext

  • Trong thư mục Models bạn tạo một lớp DbContext (là lớp đại diện để truy vấn dữ liệu từ cơ sở dữ liệu) như sau:
  • Trên cửa sổ Add New Item chọn Installed => Visual C# => Data => ADO.NET Entity Data Model. Đặt tên cho lớp này: ProductDBContext.
  • Sau đó chọn Add để tạo mới lớp này.
  • Trên cửa sổ Entity Data Model Wizard chọn Code First from database sau đó chọn Next.
  • Trên cửa sổ Choose your Data Connection chọn New Connection, ở cửa sổ Connection Properties giờ bạn nhập thông tin Database vừa tạo ở trên vào. Sau đó chọn OK.
  • Sau khi chọn xong Database bạn để ý những chỗ sau: sau khi bạn chọn database xong EF sẽ tự sinh cho 1 chuỗi connectionString để kết nối vào database của bạn, chuỗi này sẽ được lưu trong file Web.Config mình có nói ở phần trước. Sau khi tạo bạn cũng có thể kiểm tra lại trong file này. Chọn Next để tiếp tục.
  • Next đến khi Finish.
  • Trong file Web.config sẽ có thêm thẻ connectionStrings
  • Trong file ProductDBContext.cs bạn xem code sau:


namespace ProductManagement.Models { using System; using System.Data.Entity; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; public partial class ProductDBContext : DbContext { public ProductDBContext() : base("name=ProductDBContext") { } public DbSet Products { get; set; } public DbSet

CategoryOfProducts { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { } } }

Tạo mới CategoryOfProductController

  • Trước khi tạo Controller mới bạn cần build project để những model bạn mới tạo được bằng cách nhấn tổ hợp Ctrl + Shift + B hoặc trên thanh toolbar chọn Build => Build Solution.
  • Trong thư mục Controllers tạo mới controller.
  • Chọn MVC 5 Controller with views using EntityFramework.
  • Sau đó bạn chọn tương tự như hình EF sẽ tự tạo cho bạn CategoryOfProductController.
  • Sau khi tạo Controller bạn sẽ thấy trong Views sẽ tự động được tạo thêm một thư mục CategoryOfProduct trong này sẽ chứa Views của CategoryOfProduct.

Thêm đường dẫn của Views vào Layout

  • Trong thư mục Views => Shared => _Layout.cshtml
  • Bạn thêm dòng code này vào

  • @Html.ActionLink("Category Of Product", "Index", "CategoryOfProducts")

Tạo mới ProductController

  • Làm tương tự như tạo CategoryOfProductController
  • Thêm đường dẫn đến Products

  • @Html.ActionLink("Products", "Index", "Products")

  • vào Layout.

  • Và giờ chạy ứng dụng…
  • Phần hiển thị bạn có thể custom theo 2 cách như sau:

    • Bạn thêm DisplayName cho các fields trong model(recommend).
    • Custom lại phần view.
      Trong file Products => Index.cshtml
  • Bạn thêm DisplayName cho các fields trong model(recommend).

Sử dụng Code first Migrations.

  • Enable Migration

    • Mở cửa sổ làm việc Package mangager consoles nhập đoạn code này

      Enable-Migrations

      để thực enable migration.
    • Sau khi enable xong thư mục Migrations sẽ tự động được tạo ra, trong đó có file Initial Create và Configuration
  • Mở cửa sổ làm việc Package mangager consoles nhập đoạn code này
  • Khởi tạo dữ liệu

    • Trong file Configuration insert đoạn code sau vào phướng thức Seed


      // You can use the DbSet

      .AddOrUpdate() helper extension method // to avoid creating duplicate seed data. context.CategoryOfProducts.AddOrUpdate(c => c.CategoryOfProductID, new Models.CategoryOfProduct{ CategoryOfProductID = 1, Description = @"Đồ điện tử" }, new Models.CategoryOfProduct { CategoryOfProductID = 2, Description = @"Đồ nhà bếp"} ); context.Products.AddOrUpdate(p => p.ProductID, new Models.Product { ProductID = 1, NameOfProduct = @"Quạt điện", CategoryOfProductID = 1}, new Models.Product { ProductID = 2, NameOfProduct = @"Chảo", CategoryOfProductID = 2} );

  • Để insert dữ liệu khởi tạo vào database thực hiện UpdateDatabase chèn đoạn code sau vào Package mangager consoles


    Update-Database

  • Sau khi update xong vào SQL để xem đã insert được vào cơ sở dữ liệu chưa sử dụng Server Explorer trên VS.

  • Kết nối với CSDL ProductManagement

  • Dữ liệu đã được insert vào như thế này

  • Sau khi thêm dữ liệu chạy thử thấy phát sinh vấn đề như dưới đây: thông thường ở cột mã loại sản phẩm sẽ hiển thị ra tên loại sản phẩm chứ không hiển thị sang ID như thế kia. Bài viết hơi dài, vì vậy mình sẽ hướng dẫn tạo ViewModel để hiển thị theo ý muốn ở phần sau nhé.

All rights reserved

Getting Started with Entity Framework 6 Code First using MVC 5

The basics of using Entity Framework 6 to display and edit data in an ASP.NET MVC 5 application.

  • Creating an Entity Framework Data Model
  • Implementing Basic CRUD Functionality
  • Sorting, Filtering, and Paging
  • Connection Resiliency and Command Interception
  • Code First Migrations and Deployment
  • Creating a More Complex Data Model
  • Reading Related Data
  • Updating Related Data
  • Async and Stored Procedures
  • Handling Concurrency
  • Implementing Inheritance
  • Advanced Entity Framework Scenarios
EP 1 Complete Employees Management System Using ASPNET Core MVC, EF Core,SQL|AdminLTE| Perform CRUD💥
EP 1 Complete Employees Management System Using ASPNET Core MVC, EF Core,SQL|AdminLTE| Perform CRUD💥

Create controller and views

Now you’ll create a web page to display data. The process of requesting the data automatically triggers the creation of the database. You’ll begin by creating a new controller. But before you do that, build the project to make the model and context classes available to MVC controller scaffolding.

  1. Right-click the Controllers folder in Solution Explorer, select Add, and then click New Scaffolded Item.

  2. In the Add Scaffold dialog box, select MVC 5 Controller with views, using Entity Framework, and then choose Add.

  3. In the Add Controller dialog box, make the following selections, and then choose Add:

    • Model class: Student (ContosoUniversity.Models). (If you don’t see this option in the drop-down list, build the project and try again.)

    • Data context class: SchoolContext (ContosoUniversity.DAL).

    • Controller name: StudentController (not StudentsController).

    • Leave the default values for the other fields.

      When you click Add, the scaffolder creates a StudentController.cs file and a set of views (.cshtml files) that work with the controller. In the future when you create projects that use Entity Framework, you can also take advantage of some additional functionality of the scaffolder: create your first model class, don’t create a connection string, and then in the Add Controller box specify New data context by selecting the + button next to Data context class. The scaffolder will create your


      DbContext

      class and your connection string as well as the controller and views.

  4. Visual Studio opens the Controllers\StudentController.cs file. You see that a class variable has been created that instantiates a database context object:


    private SchoolContext db = new SchoolContext();

    The


    Index

    action method gets a list of students from the Students entity set by reading the

    Students

    property of the database context instance:

    public ViewResult Index() { return View(db.Students.ToList()); }

    The Student\Index.cshtml view displays this list in a table:

    @foreach (var item in Model) {

    }

    @Html.DisplayNameFor(model => model.LastName) @Html.DisplayNameFor(model => model.FirstMidName) @Html.DisplayNameFor(model => model.EnrollmentDate)
    @Html.DisplayFor(modelItem => item.LastName) @Html.DisplayFor(modelItem => item.FirstMidName) @Html.DisplayFor(modelItem => item.EnrollmentDate) @Html.ActionLink("Edit", "Edit", new { id=item.ID }) | @Html.ActionLink("Details", "Details", new { id=item.ID }) | @Html.ActionLink("Delete", "Delete", new { id=item.ID })

  5. Press Ctrl+F5 to run the project. (If you get a “Cannot create Shadow Copy” error, close the browser and try again.)

    Click the Students tab to see the test data that the


    Seed

    method inserted. Depending on how narrow your browser window is, you’ll see the Student tab link in the top address bar or you’ll have to click the upper right corner to see the link.

Set up EF 6 to use LocalDB

LocalDB is a lightweight version of the SQL Server Express database engine. It’s easy to install and configure, starts on demand, and runs in user mode. LocalDB runs in a special execution mode of SQL Server Express that enables you to work with databases as .mdf files. You can put LocalDB database files in the App_Data folder of a web project if you want to be able to copy the database with the project. The user instance feature in SQL Server Express also enables you to work with .mdf files, but the user instance feature is deprecated; therefore, LocalDB is recommended for working with .mdf files. LocalDB is installed by default with Visual Studio.

Typically, SQL Server Express is not used for production web applications. LocalDB in particular is not recommended for production use with a web application because it’s not designed to work with IIS.

  • In this tutorial, you’ll work with LocalDB. Open the application Web.config file and add a


    connectionStrings

    element preceding the

    appSettings

    element, as shown in the following example. (Make sure you update the Web.config file in the root project folder. There’s also a Web.config file in the Views subfolder that you don’t need to update.)

The connection string you’ve added specifies that Entity Framework will use a LocalDB database named ContosoUniversity1.mdf. (The database doesn’t exist yet but EF will create it.) If you want to create the database in your App_Data folder, you could add

AttachDBFilename=|DataDirectory|\ContosoUniversity1.mdf

to the connection string. For more information about connection strings, see SQL Server Connection Strings for ASP.NET Web Applications.

You don’t actually need a connection string in the Web.config file. If you don’t supply a connection string, Entity Framework uses a default connection string based on your context class. For more information, see Code First to a New Database.

Chấm thi cuối kỳ Vi tích phân 1C hệ đại trà | Phòng thi E204-Part01 | Học kỳ 1 2023-2024 | HCMUS
Chấm thi cuối kỳ Vi tích phân 1C hệ đại trà | Phòng thi E204-Part01 | Học kỳ 1 2023-2024 | HCMUS

Set up the site style

A few simple changes will set up the site menu, layout, and home page.

  1. Open Views\Shared\_Layout.cshtml, and make the following changes:

    • Change each occurrence of “My ASP.NET Application” and “Application name” to “Contoso University”.
    • Add menu entries for Students, Courses, Instructors, and Departments, and delete the Contact entry.

    The changes are highlighted in the following code snippet:


    <br /> @ViewBag.Title - Contoso University<br />
    @Styles.Render("~/Content/css") @Scripts.Render("~/bundles/modernizr")

    @Html.ActionLink("Contoso University", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })

    • @Html.ActionLink("Home", "Index", "Home")
    • @Html.ActionLink("About", "About", "Home")
    • @Html.ActionLink("Students", "Index", "Student")
    • @Html.ActionLink("Courses", "Index", "Course")
    • @Html.ActionLink("Instructors", "Index", "Instructor")
    • @Html.ActionLink("Departments", "Index", "Department")
    @RenderBody()

    © @DateTime.Now.Year - Contoso University

    @Scripts.Render("~/bundles/jquery") @Scripts.Render("~/bundles/bootstrap") @RenderSection("scripts", required: false)


  2. In Views\Home\Index.cshtml, replace the contents of the file with the following code to replace the text about ASP.NET and MVC with text about this application:


    @{ ViewBag.Title = "Home Page"; }

    Contoso University

    Keywords searched by users: mvc 5 entity framework

    Tutorial: Get Started With Entity Framework 6 Code First Using Mvc 5 |  Microsoft Learn
    Tutorial: Get Started With Entity Framework 6 Code First Using Mvc 5 | Microsoft Learn
    Tutorial: Get Started With Entity Framework 6 Code First Using Mvc 5 |  Microsoft Learn
    Tutorial: Get Started With Entity Framework 6 Code First Using Mvc 5 | Microsoft Learn
    Tutorial: Get Started With Entity Framework 6 Code First Using Mvc 5 |  Microsoft Learn
    Tutorial: Get Started With Entity Framework 6 Code First Using Mvc 5 | Microsoft Learn
    Mvc 5 Crud Operation Using Entity Framework 6
    Mvc 5 Crud Operation Using Entity Framework 6
    Tutorial: Get Started With Entity Framework 6 Code First Using Mvc 5 |  Microsoft Learn
    Tutorial: Get Started With Entity Framework 6 Code First Using Mvc 5 | Microsoft Learn
    Mvc5 Controller With Views Using Ef - Youtube
    Mvc5 Controller With Views Using Ef - Youtube
    Series Asp.Net Mvc - Part 2: Tạo Ứng Dụng Web Với Entity Framework 6 Code  First Mvc 5
    Series Asp.Net Mvc - Part 2: Tạo Ứng Dụng Web Với Entity Framework 6 Code First Mvc 5
    Asp.Net Mvc 5 - Bài 8: Kết Nối Với Cơ Sở Dữ Liệu Bằng Entity Framework -  Đơn Giản, Dễ Sử Dụng - Youtube
    Asp.Net Mvc 5 - Bài 8: Kết Nối Với Cơ Sở Dữ Liệu Bằng Entity Framework - Đơn Giản, Dễ Sử Dụng - Youtube
    Entity Framework 6 Code First Using Mvc 5 - Gyanendu Shekhar'S Blog
    Entity Framework 6 Code First Using Mvc 5 - Gyanendu Shekhar'S Blog
    Một Số Ebook Để Học Asp.Net Mvc | Dammio
    Một Số Ebook Để Học Asp.Net Mvc | Dammio
    Basic Crud (Create, Read, Update, Delete) In Asp.Net Mvc Using C# And Entity  Framework - Geeksforgeeks
    Basic Crud (Create, Read, Update, Delete) In Asp.Net Mvc Using C# And Entity Framework - Geeksforgeeks
    Crud Operation In Asp Net Core Mvc 5 Using Entity Framework Core With  Repository Pattern
    Crud Operation In Asp Net Core Mvc 5 Using Entity Framework Core With Repository Pattern
    Let'S Build - Asp.Net Mvc 5 Todolist With Entity Framework And Identity -  Steve Woods' .Net Blog | Software Development Blog
    Let'S Build - Asp.Net Mvc 5 Todolist With Entity Framework And Identity - Steve Woods' .Net Blog | Software Development Blog
    Asp.Net Mvc 5 Linq To Sql
    Asp.Net Mvc 5 Linq To Sql
    Insertupdatedelete In Asp.Net Mvc 5 Without Entity Framework
    Insertupdatedelete In Asp.Net Mvc 5 Without Entity Framework
    Mvc 5 Tutorial Lab 10 - Entity Framework Overview- Asp.Net Mvc קורס תכנות -  Youtube
    Mvc 5 Tutorial Lab 10 - Entity Framework Overview- Asp.Net Mvc קורס תכנות - Youtube
    Tutorial: Get Started With Entity Framework 6 Code First Using Mvc 5 |  Microsoft Learn
    Tutorial: Get Started With Entity Framework 6 Code First Using Mvc 5 | Microsoft Learn

    See more here: kientrucannam.vn

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *