首页 > 其他 > 详细

EF的增删改查

时间:2014-03-27 01:20:10      阅读:662      评论:0      收藏:0      [点我收藏+]

EF的增删改查:

 

using System;

using System.Collections.Generic;

using System.Data.Entity.Infrastructure;

using System.Linq;

using System.Linq.Expressions;

using System.Text;

using System.Threading.Tasks;

 

namespace Dal

{

    publicclassStudentsDal

    { 

        zzEntities zzDB = new zzEntities();

        publicintAdd(Student model)

        {

         

           zzDB.Students.Add(model);

           returnzzDB.SaveChanges();

 

        }

 

        publicintDeleteStu(Student model) {

          

           zzDB.Students.Attach(model);

           zzDB.Students.Remove(model);

            returnzzDB.SaveChanges();

        }

 

        publicintUpdateStu(Student model,string[]propertys) {

 

          DbEntityEntry dbEE = zzDB.Entry(model);

         dbEE.State = System.Data.EntityState.Unchanged;

          foreach(var pro inpropertys)

          {

             dbEE.Property(pro).IsModified = true;

          }

 

          returnzzDB.SaveChanges();

       

        }

 

        publicintDeleteStuBy(Expression<Func<Student,bool>>delWhere) {

       

          List<Student>stuList =  zzDB.Students.Where(delWhere).ToList();

           stuList.ForEach(stu =>zzDB.Students.Remove(stu));

            returnzzDB.SaveChanges();

        }

 

        publicList<Student>GetListBy(Expression<Func<Student,bool>>stuWhere) {

 

          return  zzDB.Students.Where(stuWhere).ToList();

       

        }

 

 

        publicList<Student>GetPageList<Tkey>(intPageIndex,int PageSize,Expression<Func<Student,bool>>stuwhere,Expression<Func<Student,Tkey>> orderBy ) {

 

           returnzzDB.Students.Where(stuwhere).OrderBy(orderBy).Skip((PageIndex-1)*PageSize).Take(PageSize).ToList();

       

        }

 

    }

}

EF的增删改查,布布扣,bubuko.com

EF的增删改查

原文:http://blog.csdn.net/asdfqwer1314/article/details/22196399

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!