csharp 在asp.net mvc中实现存储库模式

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 在asp.net mvc中实现存储库模式相关的知识,希望对你有一定的参考价值。

namespace didongexpress.repos
{
    public interface IRepository : IDisposable
    {

    }

    public interface IRepository<T> : IRepository where T : class
    {
        IQueryable<T> Query(Expression<Func<T, bool>> predicate);
        List<T> All(Expression<Func<T, bool>> predicate);        
        T GetById(object id);
        T Create(T model);        
        T Update(T model, List<Expression<Func<T, object>>> updateProperties = null);
        T Delete(T model);
        T Delete(object id);
    }

    public class GenericRepository<T> : IRepository<T> where T : class
    {
        protected bool disposed = false;
        protected ExpressDb db = null;
        protected DbSet table;
        
        public GenericRepository(ExpressDb db)
        {
            this.db = db;
        }

        public IQueryable<T> Query(Expression<Func<T, bool>> predicate)
        {
            throw new NotImplementedException();
        }

        public virtual List<T> All(Expression<Func<T, bool>> predicate)
        {
            throw new NotImplementedException();
        }

        public virtual T Create(T model)
        {
            throw new NotImplementedException();
        }

        public virtual T Delete(object id)
        {
            throw new NotImplementedException();
        }

        public virtual T Delete(T model)
        {
            throw new NotImplementedException();
        }

        public virtual T GetById(object id)
        {
            throw new NotImplementedException();
        }

        public virtual T Update(T model, List<Expression<Func<T, object>>> updateProperties = null)
        {
            throw new NotImplementedException();
        }

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

        protected void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    if (db != null)
                    {
                        db.Dispose();
                        db = null;
                    }
                }

                disposed = true;
            }
        }
    }
}

以上是关于csharp 在asp.net mvc中实现存储库模式的主要内容,如果未能解决你的问题,请参考以下文章

csharp 在asp.net mvc中实现工作单元模式

csharp 在ASP.NET MVC中使用bundle

csharp ASP.NET MVC 5表单

csharp asp.net mvc模块属性

csharp ASP.NET MVC WebViewPageExtensions

csharp ASP.NET的助手,ASP.NET MVC应用服务器端测试