同步操作将从 dotNET China/OpenAuth.Net 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
using System;using System.Data.Entity;using System.Data.Entity.Migrations;using System.Linq;using System.Linq.Expressions;using EntityFramework.Extensions;using OpenAuth.Domain.Interface;using Infrastructure;using OpenAuth.Domain;using OpenAuth.Repository.Models;namespace OpenAuth.Repository{public class UnitWork: IUnitWork{protected OpenAuthDBContext Context = new OpenAuthDBContext();/// <summary>/// 根据过滤条件,获取记录/// </summary>/// <param name="exp">The exp.</param>public IQueryable<T> Find<T>(Expression<Func<T, bool>> exp = null) where T : class{return Filter(exp);}public bool IsExist<T>(Expression<Func<T, bool>> exp) where T : class{return Context.Set<T>().Any(exp);}/// <summary>/// 查找单个/// </summary>public T FindSingle<T>(Expression<Func<T, bool>> exp) where T:class{return Context.Set<T>().AsNoTracking().FirstOrDefault(exp);}/// <summary>/// 得到分页记录/// </summary>/// <param name="pageindex">The pageindex.</param>/// <param name="pagesize">The pagesize.</param>/// <param name="orderby">排序,格式如:"Id"/"Id descending"</param>public IQueryable<T> Find<T>(int pageindex, int pagesize, string orderby = "", Expression<Func<T, bool>> exp = null) where T : class{if (pageindex < 1) pageindex = 1;if (string.IsNullOrEmpty(orderby))orderby = "Id descending";return Filter(exp).OrderBy(orderby).Skip(pagesize * (pageindex - 1)).Take(pagesize);}/// <summary>/// 根据过滤条件获取记录数/// </summary>public int GetCount<T>(Expression<Func<T, bool>> exp = null) where T : class{return Filter(exp).Count();}public void Add<T>(T entity) where T : Domain.Entity{entity.Id = Guid.NewGuid();Context.Set<T>().Add(entity);}/// <summary>/// 批量添加/// </summary>/// <param name="entities">The entities.</param>public void BatchAdd<T>(T[] entities) where T : Domain.Entity{foreach (var entity in entities){entity.Id = Guid.NewGuid();}Context.Set<T>().AddRange(entities);}public void Update<T>(T entity) where T:class{var entry = this.Context.Entry(entity);//todo:如果状态没有任何更改,会报错entry.State = EntityState.Modified;}public void Delete<T>(T entity) where T:class{Context.Set<T>().Remove(entity);}/// <summary>/// 按指定id更新实体,会更新整个实体/// </summary>/// <param name="identityExp">The identity exp.</param>/// <param name="entity">The entity.</param>public void Update<T>(Expression<Func<T, object>> identityExp, T entity) where T:class{Context.Set<T>().AddOrUpdate(identityExp, entity);}/// <summary>/// 实现按需要只更新部分更新/// <para>如:Update(u =>u.Id==1,u =>new User{Name="ok"});</para>/// </summary>/// <param name="where">The where.</param>/// <param name="entity">The entity.</param>public void Update<T>(Expression<Func<T, bool>> where, Expression<Func<T, T>> entity) where T:class{Context.Set<T>().Where(where).Update(entity);}public virtual void Delete<T>(Expression<Func<T, bool>> exp) where T : class{Context.Set<T>().Where(exp).Delete();}public void Save(){Context.SaveChanges();}private IQueryable<T> Filter<T>(Expression<Func<T, bool>> exp) where T : class{var dbSet = Context.Set<T>().AsQueryable();if (exp != null)dbSet = dbSet.Where(exp);return dbSet;}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。