首页 > 代码库 > EF crud操作

EF crud操作

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleAppEF{    class Program    {        static void Main(string[] args)        {            testEntities context = new testEntities();            //添加实体            //t_user t = new t_user();            //t.username = "test";            //t.times = DateTime.Now;            ////添加user数据            //context.Entry(t).State = System.Data.EntityState.Added;                        //删除实体            //t_user user = new t_user();            //user.id = 6;            //数据entity数据            //context.Entry(user).State = System.Data.EntityState.Deleted;            //修改实体            //t_user user = new t_user();            //user.id = 5;            //user.username = "ssss";            //context.Entry(user).State = System.Data.EntityState.Modified;            //联合插入实体            UserInfo user = new UserInfo();            user.username = "123456";            user.times = DateTime.Now;            context.Entry(user).State = System.Data.EntityState.Added;            OrderInfo order = new OrderInfo();            order.orderName = "orderName";            //外键插入            order.UserInfo = user;            context.Entry(order).State = System.Data.EntityState.Added;            context.SaveChanges();        }    }}

 

EF crud操作