Since we have already created the database, it seems logical to use a scaffolding mechanism to generate the data model from the database structure. The next step is to create a data model of our application. Go to menu Main menu > Tools > NuGet Package Manager > Manager NuGet Packages For Solution and input. Since we are making a Web API Сore application, we should install NuGet package. Creating ASP.NET Core WEB API Application Note! We have created a FOREIGN KEY FK_Prices_Products with the CASCADE delete rule so that the MS SQL server be able to provide data integrity between the Products and Prices tables on deleting records from the Products table. The relationship between these tables can be represented schematically: The Prices table consists of a list of prices. The SKU field is for searching for products in the list. The Products table consists of a products list. Now we have a database with the name SpeedUpCoreAPIExampleDB, filled with the test data. INSERT INTO Prices (,, ) VALUES ( 3, 170, ' Garmin') INSERT INTO Prices (,, ) VALUES ( 3, 165, ' LG') INSERT INTO Prices (,, ) VALUES ( 3, 160, ' Bosch') INSERT INTO Prices (,, ) VALUES ( 2, 150, ' Garmin') INSERT INTO Prices (,, ) VALUES ( 2, 145, ' LG') INSERT INTO Prices (,, ) VALUES ( 2, 140, ' Bosch') INSERT INTO Prices (,, ) VALUES ( 1, 130, ' Garmin') INSERT INTO Prices (,, ) VALUES ( 1, 125, ' LG') INSERT INTO Prices (,, ) VALUES ( 1, 100, ' Bosch') INSERT INTO Products (, ) VALUES ( ' abc', ' Product3') INSERT INTO Products (, ) VALUES ( ' aab', ' Product2') GO INSERT INTO Products (, ) VALUES ( ' aaa', ' Product1') INT IDENTITY ( 1, 1) NOT NULL,ĬONSTRAINT PRIMARY KEY CLUSTERED ( ASC) Let us create a database for our application and fill it with test data and execute the next query in the Microsoft SQL Server Management Studio: In our application, we use a Microsoft SQL Server. This pattern provides maximum decoupling of application layers and makes it easy to develop and test the application. If the Service needs some data, it requests the Repository without knowing where and how the data is stored. All methods of receiving the data from or storing the data in a database are encapsulated in Repositories. The controller does not care about the type of service result and just transmits it to the user with the http response. After processing a request, a service returns a result of IActionResult type to a controller. By convention, we named classes that encapsulate business logic as “Services”. We will build our WEB API application using Controllers – Services – Repositories – Database architecture.Ĭontrollers are responsible for routing – they accept http requests and invoke appropriate methods of services with parameters received from the request parameters or body. Working with the database using Entity Framework Core (EFC).Creating a database in Microsoft SQL Server.Controllers – Services – Repositories – Database architecture.NET Core 2.1) and Microsoft SQL Server (any version). In Part 1, we will create an asynchronous RESTful WEB API service that be able to search products in a database and get price lists of different suppliers for the particular product.įor coding, we need Microsoft Visual Studio 2017 (updated to. Deep refactoring and refinement of ASP.NET Core WEB API application code Using various approaches to increase the application's productivity Creating a test RESTful WEB API application The main focus will be on the application productivity. In this article, we review the process of creating ASP.NET WEB API application using ASP.NET Core.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |