zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    flask总结02
    flask总结01
    恩智浦Freescale Cortex-A9 迅为IMX6开发板平台初体验
    [分享] IMX6嵌入式开发板linux QT挂载U盘及TF卡
    迅为4412嵌入式安卓开发板兼容3G网络|4G网络
    迅为嵌入式4412平台兼容3G/4G模块的安卓开发板
    飞思卡尔开发板-迅为IMX6开兼容单核 双核 四核Plus开发板
    物联网初学者智能家居必备迅为iTOP-4412开发板
    【分享】4412开发板POP烧写ubuntu出错,如何挂载emmc分区解决方法
    [安卓开发板]迅为IMX6 四核Android开发板
  • 原文地址:https://www.cnblogs.com/SeNaiTes/p/9345831.html
Copyright © 2011-2022 走看看