• EF增删改查


    //添加

    using (WanWeiTiKuEntities WanweiTiku = new WanWeiTiKuEntities())
    {
    tk_ShiJuanLeiXin Leixing = new tk_ShiJuanLeiXin()
    {
    LeiXing_Name = TxtLeixing.Text.Trim(),
    KeCheng_id = Frmain.SelectKechengId
    };
    WanweiTiku.tk_ShiJuanLeiXin.Add(Leixing);
    WanweiTiku.SaveChanges();
    }

    //删除

    WanWeiTiKuEntities WanweiTiku = new WanWeiTiKuEntities();
    var rmZhishidian = (from u in WanweiTiku.tk_ZhiShiDian
    where u.ZhiShiDian_id == 1
    select u).ToList();
    foreach (var item in rmZhishidian)
    {
    WanweiTiku.tk_ZhiShiDian.Remove(item);
    }
    WanweiTiku.SaveChanges();

    //修改

    WanWeiTiKuEntities WanweiTiku = new WanWeiTiKuEntities();

    var result = from u in WanweiTiku.tk_Student

     select u;

    ////使用循环方式,修改所有查询到的记录
    foreach (var item in result)
    {
     item.Age = 10;
    }

    WanweiTiku .SaveChanges();

    //查询

    //使用匿名类查询多个字段

    WanWeiTiKuEntities WanweiTiku = new WanWeiTiKuEntities();

    var result = from p in WanweiTiku.Student
                      where p.ID < 4
                      select new { p.ID, p.Name };

    foreach (var item in result)
    {
    ////这里无法输出年龄
    Console.WriteLine("ID:{0},姓名:{1}。", item.ID, item.Name);
    }

  • 相关阅读:
    开发趋势
    常用的meta
    meta基础
    HTTP请求方法GET和POST
    same-origin policy----wikipedia
    跨域——同源策略(译)
    DNS问答
    TCP/IP的整理
    鉴权方法
    Web攻击技术---OWASP top
  • 原文地址:https://www.cnblogs.com/hcw136156133/p/3614480.html
Copyright © 2020-2023  润新知