SOD框架的Model连接数据库及增删改查

Posted senaites

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SOD框架的Model连接数据库及增删改查相关的知识,希望对你有一定的参考价值。

using PWMIS.DataMap.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PWMIS.Common;

namespace GoOver.Models
{
    [Serializable()]
    public partial class Stu : EntityBase
    {
        public Stu()
        {
            TableName = "Stu";
            Schema = "";
            EntityMap = EntityMapType.Table;
            //IdentityName = "标识字段名";
            IdentityName = "Id";
            //PrimaryKeys.Add("主键字段名");
            PrimaryKeys.Add("Id");
        }
        protected override void SetFieldNames()
        {
            PropertyNames = new string[] { "Id", "Name", "Sex", "CreateTime", "IsDelete" };
        }

        protected override string[] SetFieldDescriptions()
        {
            //字段对应的描述
            return new string[] { "主键", "名称", "性别", "创建时间", "删除标志" };
        }
        public System.Int32 Id
        {
            get { return getProperty<System.Int32>("Id"); }
            set { setProperty("Id", value); }
        }
        public System.String Name
        {
            get { return getProperty<System.String>("Name"); }
            set { setProperty("Name", value); }
        }
        public System.Boolean Sex
        {
            get { return getProperty<System.Boolean>("Sex"); }
            set { setProperty("Sex", value); }
        }
        public System.DateTime CreateTime
        {
            get { return getProperty<System.DateTime>("CreateTime"); }
            set { setProperty("CreateTime", value); }
        }
        public System.Boolean IsDelete
        {
            get { return getProperty<System.Boolean>("IsDelete"); }
            set { setProperty("IsDelete", value); }
        }
    }
}

  PDF.NET SOD连接数据库只支持明文写在config文件的:

<configuration>
  <connectionStrings>
    <add name="StudentDB" connectionString="Data Source=.;Initial Catalog=StudentDB;Integrated Security=False;User ID=sa;Password=123;max pool size=1" providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

可以研究下这个:https://blog.csdn.net/qqcxw/article/details/51927469

//查询:
UserTab user = new  UserTab(){UserID = 1};
OQL q=OQL.From(User).select().Where(User.UserID).END;
UserTab dbUser = EntityQuery<UserTab>.QueryObject(q);
//查询2:
 List<Stu> LStu = new List<Stu>();
            var StuList = OQL.FromObject<Stu>().Select().Where((x, c) => x.Comparer(c.IsDelete, "=", false)).END.ToList();
//删除:相当于:Delete from [UserTab] where [UserID] = 2
UserTab user = new UserTab();
OQL deleteQ = OQL.From(user).Delete().Where(cmp => cmp.Comparer(user.UserID,OQLCompare.comUserTab>.Instance.ExecuteOql(deleteQ);
//更新整个实体:
UserTab user = new UserTab(){UserID = 1 ,UserName = "张三",pwd="XXX"};
//更新某个字段:相当于:update [UserTab] set [UserName] = "李四",[pwd] = "XXX" where [UserID] = 1
UserTab user = new  UserTab(){UserID = 1,UserName="李四",pwd="XXX"};
OQL updateQ = OQL.From(user).Update(user.UserName).END;
EntityQuery<UserTab>.Instance.ExecuteOql(updateQ);//只更新姓名
//插入全部数据:
UserTab user = new UserTab(){UserName = "张三",pwd="XXX"};
EntityQuery<UserTab>.Instance.Insert(user);
//插入部分数据:
UserTab user = new UserTab(){UserName = "张三",pwd="XXX"};
OQL insertQ = OQL.From(user).Insert(user.UserName).END;
EntityQuery<UserTab>.Instance.ExecuteOql(insertQ);

 

以上是关于SOD框架的Model连接数据库及增删改查的主要内容,如果未能解决你的问题,请参考以下文章

MyBatis入门配置及增删改查

php连接MySQL数据库及增删改查

java DMO及增删改查代码的自动生成

在 idea 下搭建的第一个MyBatis项目及增删改查用法

CDH5.15.1 hive 连接mongodb配置及增删改查

创建数据库及增删改查基本操作