Model/BaseService.cs
(开头部分) 5KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq.Expressions;
using System.Runtime.Remoting.Messaging;
public class BaseService<TEntity> where TEntity : class
{
//确保线程中EF唯一,不出现数据脏读
BaseDBContext db
{
get
{
object obj = CallContext.GetData(typeof(BaseDBContext).FullName);
if (obj == null)
{
obj = new BaseDBContext();
CallContext.SetData(typeof(BaseDBContext).FullName, obj);
}
return obj as BaseDBContext;
}
}
DbSet<TEntity> _dbset;
public BaseService()
{
_dbset = db.Set<TEntity>();
}
#region 查询方法
public List<TEntity> QueryWhere(Expression<Func<TEntity, bool>> where)
{
return _dbset.Where(where).ToList();
}
public List<TEntity> QueryWhereAsNoTracking(Expression<Func<TEntity, bool>> where)
{
return _dbset.AsNoTracking().Where(where).ToList();
}
public List<TEntity> QueryOrderBy<TKey>(Expression<Func<TEntity, bool>> where, Expression<Func<TEntity, TKey>> order)
{
return _dbset.Where(where).OrderBy(order).ToList();
}
public List<TEntity> QueryOrderByDescending<TKey>(Expression<Func<TEntity, bool>> where, Expression<Func<TEntity, TKey>> order)
{
return _dbset.Where(where).OrderByDescending(order).ToList();
}
public List<TEntity> QueryJoin(Expression<Func<TEntity, bool>> where, string[] tableNames)
后面还有 137 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。