学习CYQ.DATA

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiajing13579/article/details/82256012

这个ORM最近开源了, 所以看一下,

一.入门指南

下载框架后解压出: 

1:CYQ.Data.dll和CYQ.Data.Xml(方法注释提示)

2:CYQ.Data.ProjectTool.exe (枚举或实体生成器)

3:API 帮助文档一份

4:更新记录.txt

5:VS集成ProjectTool说明.txt

6:智能提示

二:手工下载的,项目添加引用

把 CYQ.Data.dll添加到项目引用中(CYQ.Data.Xml 默认也会被复制引用到Bin目录中)

扫描二维码关注公众号,回复: 3257769 查看本文章

MSSQL数据库链接示例,这里我只例出了 mssql有的例子,如果看别的方式请到:

http://www.cyqdata.com/cyqdata/article-detail-411

<connectionStrings>
<add name="Conn" connectionString="server=.;database=demo;uid=sa;pwd=123456" providerName="System.Data.SqlClient"/>

<connectionStrings>

三.通过自带的工具生成 ProjectTool 生成 数据类

    这个很好理解,和别的工具如 EF,一样,可以把数据库的字段生成类.

四.单表的增,册,改

增加:

using(MAction action = new MAction(TableNames.Users))

{
        action.Set(Users.NickName, 
"路过秋天");//非UI型设值

        action.UI.GetFrom(txtUserName)//UI型设值

        if(action.Insert())

        {

           int id=action.Get<int>(Users.ID);//取回插入后的主键ID

        }
}

修改:

using(MAction action = new MAction(TableNames.Users))

{
       action.Set(Users.Password, "http://cyq1162.cnblogs.com"
);
       action.Update(1);
//更新ID为1的密码

}

using(MAction action = new MAction(TableNames.Users))

{
       action.Set(Users.Password, 
"http://cyq1162.cnblogs.com"
);
       action.Update(
"UserName='路过秋天'"
);
}

using(MAction action = new MAction(TableNames.Users))

{

        action.Set(Users.NickName, "路过秋天");//非UI型设值

        action.Update("id=1",true);//除了已赋值的,其它表字段,自动从Request["字段"]中取值。

}

删除:

using(MAction action = new MAction(TableNames.Users))

{
        action.Delete(1);
}

using(MAction action = new MAction(TableNames.Users))

{
        action.Delete(
"1,2,3"
);//批量删除
}

单表查找:

using (MAction action = new MAction("T1_SystemTime"))
            {
               
                if (action.Fill("autoID=2"))/
                {
                    MDataTable table = action.Select("autoID=2");
                    gridControl1.DataSource = table;
                }
               
              }

五.多表sql查找

 string customTable = "select t2_elderly.ElderlyID,T2_Elderly.ElderlyName,T1_Set_CareLevel.NursingRankName from t2_elderly inner join T1_Set_CareLevel on t2_elderly.CareLevelID = T1_Set_CareLevel.CareLevelID";
            int count;
            using (MAction action = new MAction(customTable))
            {

                MDataTable table = action.Select();
                gridControl1.DataSource = table;
            }

六.事务: 这个我还没有试过,不知道对不对.

  //事务
            using(MAction action = new MAction(TableNames.Users))
{
    action.BeginTransation();
 
    ...执行数据块...
可选1:action.SetTransLevel(IsolationLevel.ReadUncommitted);//自定义事务级别
可选2:action.RollBack();//事务回滚  

可选3:action.ResetTable(新表)//切换表
 
    action.EndTransation();//等同于事务Commit提交
 
    action.BeginTransation();//重新开启新事务
    ...执行语句块2...
    action.EndTransation();//提交新事务Commit提交
}

这些是对一个数据库的操作
这个 ORM 工具,还支 1.多数据库连接, 2.缓存功能,可以在这里查看:
http://www.cyqdata.com/cyqdata/article-cate-33

猜你喜欢

转载自blog.csdn.net/xiajing13579/article/details/82256012