YsuhyORM之Add方法

举例的数据表里有

Student

public int ID

public string UserName

public string Password

public int Age

public bool IsBoy

public int SchoolID

public decimal Height

public DateTime AddTime

 

School

public int ID

public string SchoolName

 

Student表里面的Height表示身高,用的decimal类型,只是为了演示一下该类型字段而已

SchoolID为学校代码外键,其它意义很明显,就不做介绍了

 

   代码如下

School school = new School();

        school.SchoolName = "复旦大学";
        school.Add();

        school.New();
        school.SchoolName = "南京大学";
        school.Add();

        school.New();
        school.SchoolName = "西安交通大学";
        school.Add();


        Student student = new Student();

        student.UserName = "小红";
        student.SchoolID = 1;
        student.Password = "xiaohong";
        student.IsBoy = false;
        student.Height = (decimal)1.623;
        student.Age = 19;
        student.AddTime = DateTime.Now;
        student.Add();

        student.New();
        student.UserName = "小刚";
        student.AddTime = DateTime.Now;
        student.Age = 17;
        student.IsBoy = true;
        student.SchoolID = 2;
        student.Add();

 

执行以上代码就可以插入数据了 School表3条 ,Student表2条

执行后结果如下

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值