码迷,mamicode.com
首页 > 其他好文 > 详细

EF crud操作

时间:2014-10-30 22:27:34      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   sp   数据   div   on   

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操作

标签:style   blog   io   color   ar   sp   数据   div   on   

原文地址:http://www.cnblogs.com/zoro-zero/p/4063662.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!