Fork me on GitHub

LINQ.CS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Zdsoft.DAL
{
   public  class LINQ
    {
       MyDataContext context = new MyDataContext();
       //context.DeferredLoadingEnabled = false;
       public IList<Student> Search(Student stu)
       {
          
           var r = (from n in context.Student where n.StudentNumber == stu.StudentNumber select n).ToList<Student>();
           return r;
       }
       public IList<Student> SearchAll()
       {       
           var r = (from n in context.Student select n).ToList<Student>();
           return r;
       }
       public IList<Major> SearchMajor()
       {
           var r = (from n in context.Major select n).ToList<Major>();
           return r;
       }
       public IList<Department> SearchDepartment()
       {
           var r = (from n in context.Department select n).ToList<Department>();
           return r;
       }
       public IList<Nationality> SearchNationality()
       {
           var r = (from n in context.Nationality select n).ToList<Nationality>();
           return r;
       }
       
       public IList<Class> SearchClss()
       {
           var r = (from n in context.Class select n).ToList<Class>();
           return r;
       }
       public void Add(Student stu)
       {
           context.Student.InsertOnSubmit(stu);
           context.SubmitChanges();
       }
       public void Up(Student ya)
       {
           var t = context.Student.Single(e => e.StudentNumber == ya.StudentNumber);
           t.StudentName = ya.StudentName;
           t.Gender = ya.Gender;
           t.Identification = ya.Identification;
           t.MajorID = ya.MajorID;
           t.Birthday = ya.Birthday;
           t.ParentName = ya.ParentName;
           t.Telephone = ya.Telephone;
           t.NationalityID = ya.NationalityID;
           t.ClassID = ya.ClassID;
           t.Address = ya.Address;
           context.SubmitChanges();
       }
       public void del(Student ya)
       {

           var s = (from n in context.Student where n.StudentNumber == (ya.StudentNumber) select n).FirstOrDefault();
           if (s != null)
           {
               context.Student.DeleteOnSubmit(s);
               context.SubmitChanges();
           }
           else
           {
               return;
           }

       }
    }
}

 

posted @ 2014-04-13 22:45  种花生的读书人  阅读(171)  评论(0编辑  收藏  举报

该博客仅作为记录笔记,转载随意