• 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);
  • 相关阅读:
    OpenCV实现基于傅里叶变换的旋转文本校正
    【来龙去脉系列】QRCode二维码的生成细节和原理
    软件License设计
    常见加密算法简析
    【来龙去脉系列】RSA算法原理
    单目相机标定原理
    CYQ.Data 支持 PostgreSQL 数据库
    ASP.NET Aries 高级开发教程:主题样式及多语言(标签化控制)
    ASP.NET Aries 高级开发教程:Excel导入之代码编写(番外篇)
    ASP.NET Aries 高级开发教程:Excel导入配置之规则说明(下)
  • 原文地址:https://www.cnblogs.com/SeNaiTes/p/9345831.html
Copyright © 2020-2023  润新知