轮子来袭 vJine.Core Orm 之 01_快速体验

  vJine.Core 是.Net环境下C#类库,在其包含的众多功能中ORM功能尤为突出,现简介如下。

一、支持的数据库:

   SQLite, MySQL, MS SQL, Oracle。

二、使用方法:

  0.添加引用:

    库文件vJine.Core.dll,

    

using vJine.Core;
using vJine.Core.ORM;

  1.定义类:

using System;
using System.Collections.Generic;
using System.Text;
using vJine.Core.Base;
using vJine.Core.IO;
using vJine.Core.ORM;

namespace vJineCore_QuickStart.BML {

    public class My_Model : ItemBase /*不是必须继承*/ {
        public My_Model() {
            this.ID = Guid.NewGuid().ToString("N");
        }

        public partial class _ {
            public static readonly Property<My_Model, string> ID = new Property<My_Model, string>("ID");
        }
        string _ID;
        [Key(IsPrimary=true)] //指定主键
        public string ID {
            get {
                return this._ID;
            }
            set {
                if (value != this._ID) {
                    this._ID = value;
                    this.NotifyPropertyChanged("ID");
                }
            }
        }

        bool _IsActive;
        public bool IsActive {
            get {
                return this._IsActive;
            }
            set {
                if (value != this._IsActive) {
                    this._IsActive = value;
                    this.NotifyPropertyChanged("IsActive");
                }
            }
        }

        public enum Status:byte {
            Unknown = 0,
            Ready = 1,
            Running = 2,
            Done = 4
        }

        Status _MyStatus;
        public partial class _ {
            public static readonly Property<My_Model, Status> MyStatus = new Property<My_Model, Status>("MyStatus");
        }
        public Status MyStatus { //支持枚举类型
            get {
                return this._MyStatus;
            }
            set {
                if (value != this._MyStatus) {
                    this._MyStatus = value;
                    this.NotifyPropertyChanged("MyStatus");
                }
            }
        }

        public partial class _ {
            public static readonly Property<My_Model, int> Qty = new Property<My_Model, int>("Qty");
        }
        int _Qty;
        public int Qty {
            get {
                return this._Qty;
            }
            set {
                if (value != this._Qty) {
                    this._Qty = value;
                    this.NotifyPropertyChanged("Qty");
                }
            }
        }

        DateTime _Stamp;
        public DateTime Stamp {
            get {
                return this._Stamp;
            }
            set {
                if (value != this._Stamp) {
                    this._Stamp = value;
                    this.NotifyPropertyChanged("Stamp");
                }
            }
        }
    }
}

  2.配置连接:

    

<connectionStrings>
    <add name="Default" providerName="System.Data.SqlClient" connectionString="Data Source=.;Initial Catalog=【数据库名称】;Integrated Security=True"/>
  </connectionStrings>

注:请将【数据库名称】改为你本地对应的数据库名。

  3.新建实例:

    

DataManager dm = new DataManager(); //引用Default配置

DataManager dm = new DataManager("specific_name"); //引用指定配置

  4.创建数据表:

    

//Create Table
dm.Create<My_Model>();

  5.增删改查:

My_Model new_data = new My_Model() {
                        Qty = 0, IsActive = false, MyStatus = My_Model.Status.Ready
                    };
                    new_data.Stamp = dm.Now;
                    dm.I<My_Model>(new_data);
dm.D<BML.My_Model>(BML.My_Model._.ID == "xxx");
dm.U<BML.My_Model>(My_Model._.Qty.EQ(My_Model._.Qty + 1) & My_Model._.MyStatus.EQ(My_Model.Status.Running), My_Model._.MyStatus == My_Model.Status.Ready);
List<My_Model> container = new List<My_Model>(); 
                //先定义一个实现IList<>接口的对象容器,查询结果将累加填充
                dm.Q<My_Model>(container, My_Model._.ID.Like("ABC%") & My_Model._.Qty > 0);

三、附件:

   1、vJine.Core

四、附注:

  1、默认连接配置为 MS SQL Server,未保证测试顺利进行,请优先使用MS SQL Server, connectionString请依据您服务器的实际情况更改。

  2、本篇仅作为功能体验的引导文章,后续将陆续推出使用细则、架构设计等相关内容。

  3、vJine.Core将已开源模式提供,可用免费于私人和商业用途,但作者本人不反使用者通过以下方式给以赞同(顶贴、点赞、推荐)。

  4、关于性能:性能方面个人暂无比较,如有热衷于这方面的朋友帮忙做个测试,将不胜感激。

  5、vJine.Core的目标是:简洁、高效、轻量级、非侵入。

原文地址:https://www.cnblogs.com/vjine/p/vJine_Core_Orm_01.html