ServiceStack. OrmLite (1), servicestack. ormlite
Software environment:
- Win7 x64 SP1
- SQL Server 2008r2
- Visual maxcompute 2017 Professional
Objective: To retrieve and display all records in the table Roles of the ReportServer In the example database.
Steps:
1. Add a software package
Use NuGet to add the following packages:
ServiceStack
ServiceStack. OrmLite
Ii. Define table classes
Define the corresponding C # Class Based on the table Roles:
[Serializable] [Alias("Roles")] public class Role { public string RoleID { get; set; } public string RoleName { get; set; } public string Description { get; set; } public string TaskMask { get; set; } public int RoleFlags { get; set; } }
3. Obtain and output table data
var dbFactory = new OrmLiteConnectionFactory("Server=(local);Database=ReportServer;Trusted_Connection=True;", SqlServerDialect.Provider); using(var db = dbFactory.Open()) { var roles = db.Select<Role>(); "Roles: {0}".Print(roles.Dump()); }
The complete code is as follows:
// RolesDemo.cs
using System;using ServiceStack.Text; // for string.Print()using ServiceStack.OrmLite;using ServiceStack.DataAnnotations; // for [Alias()]namespace ConsoleApp1{ [Serializable] [Alias("Roles")] public class Role { public string RoleID { get; set; } public string RoleName { get; set; } public string Description { get; set; } public string TaskMask { get; set; } public int RoleFlags { get; set; } } class RolesDemo { public static void Run() { var dbFactory = new OrmLiteConnectionFactory("Server=(local);Database=ReportServer;Trusted_Connection=True;", SqlServerDialect.Provider); using(var db = dbFactory.Open()) { var roles = db.Select<Role>(); "Roles: {0}".Print(roles.Dump()); } } }}
// Program.cs
using System;namespace ConsoleApp1{ class Program { static void Main(string[] args) { RolesDemo.Run(); } }}