ServiceStack. OrmLite (1), servicestack. ormlite

Source: Internet
Author: User

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();        }    }}

 

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.