初次使用Chloe(本人小白)

231 阅读1分钟

Chloe是一个国产的orm

因为公司在用。所以,必须学会如何使用,那么我就写了一个查询的简单使用

Chloe官网:www.52chloe.com/

使用语言:C#

环境:.net core 2.0 (当前使用) (貌似支持所有环境,我就不多说了)

这个ORM的优劣在官网已经说的很清楚了,我就不复制过来了,给你们一个链接:

www.52chloe.com/Wiki/Docume…

\

第一步:NuGet导入这些程序集

第二步:开始上代码

using Chloe;
using Chloe.SqlServer;
using System;
using System.ComponentModel.DataAnnotations.Schema;


namespace ChloeUse
{
    class Program
    {
        static void Main(string[] args)
        {
            string connString = "这里写你的连接字符串";
            MsSqlContext context = new MsSqlContext(connString);
            context.PagingMode = PagingMode.OFFSET_FETCH;
            //上面3条是必须要有的
            IQuery<User> q = context.Query<User>();
            //lambda表达式,lambda不懂的看我lambda文档,见文章结尾
            var s = q.Where(a => a.Id == 1).ToList();
            foreach (var item in s)
            {
                Console.WriteLine("id:{0}/t名字:{1}",item.Id,item.Name);
            }
        }
    }


    [Table("User")]
    public class User
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
}

Ok大家去试试看吧,应该是管用的

Lambda表达式:blog.csdn.net/qq_36051316…\

\