Accessing data with OrmLite
In this recipe, we will learn how to get data from a database with the OrmLite Micro ORM in ASP.NET Core.
Getting ready
The code is almost the same as the previous recipe; there are only a few changes.
How to do it...
- First, we will create three folders:
Controllers
,Models
, andViews
. - Next, we add the following NuGet packages to the dependencies in the project:
"Microsoft.AspNetCore.Server.IISIntegration", "Microsoft.AspNetCore.Server.Kestrel", "Microsoft.AspNetCore.Mvc", "Microsoft.AspNetCore.Razor.Tools", "Microsoft.Extensions.Configuration.EnvironmentVariables","Microsoft.Extensions.Configuration.Json", "System.Data.Common", "System.Data.SqlClient", "ServiceStack.OrmLite.SqlServer"
- Next, let's create an
appsettings.config
file to add our database connection string and add the following code:
{ "ConnectionStrings": { "CookBookConnection": "Data Source=PC-HOME\SQLEXPRESS;Initial Catalog=CookBook;Integrated Security=True;MultipleActiveResultSets...