zoukankan      html  css  js  c++  java
  • IDispose接口实现

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Data;
    using ContosoUniversity.Models;

    namespace ContosoUniversity.DAL
    {
        public class StudentRepository : IStudentRepository, IDisposable

        {
            private SchoolContext context;

            public StudentRepository(SchoolContext context)
            {
                this.context = context;
            }

            public IEnumerable<Student> GetStudents()
            {
                return context.Students.ToList();
            }

            public Student GetStudentByID(int id)
            {
                return context.Students.Find(id);
            }

            public void InsertStudent(Student student)
            {
                context.Students.Add(student);
            }

            public void DeleteStudent(int studentID)
            {
                Student student = context.Students.Find(studentID);
                context.Students.Remove(student);
            }

            public void UpdateStudent(Student student)
            {
                context.Entry(student).State = EntityState.Modified;
            }

            public void Save()
            {
                context.SaveChanges();
            }

            private bool disposed = false;

            protected virtual void Dispose(bool disposing)
            {
                if (!this.disposed)
                {
                    if (disposing)
                    {
                        context.Dispose();
                    }
                }
                this.disposed = true;
            }

            public void Dispose()
            {
                Dispose(true);
                GC.SuppressFinalize(this);
            }
        }
    }

  • 相关阅读:
    react项目中如何解决同时需要多个请求问题
    jq+ajax+bootstrap改写一个动态分页的表格
    Window7+vs2008+QT环境搭建
    mssql charindex
    解决NTLDR is missing,系统无法启动的方法
    基于三汇语音卡的呼叫中心开发(一)
    Wince 或Windows平台 C#调用Bitmap对象后资源应该如何释放
    Anki:插件开发
    java.lang.ClassNotFoundException: com.opensymphony.xwork2.util.ValueStack
    struts2中action之间的一种跳转
  • 原文地址:https://www.cnblogs.com/swarb/p/9924314.html
Copyright © 2011-2022 走看看