• 微信公众号:美女很有趣。 工作之余,放松一下,关注即送10G+美女照片!

BaseDAL

开发技术 开发技术 1周前 (11-24) 5次浏览

public class BaseDAL<T> where T:class
{
/// <summary>
/// 数据上下文(所有操作基于model)
/// </summary>
public Model1 model
{
get { return new Model1(); }
}
/// <summary>
/// 查询集合
/// </summary>
/// <param name=”Expression”>表达式</param>
/// <returns>List集合</returns>
public List<T> Select(Expression<Func<T,bool>>Expression)
{
return model.Set<T>().Where(Expression).ToList();
}

/// <summary>
/// 查询单个对象
/// </summary>
/// <param name=”Expression”>表达式</param>
/// <returns>单个对象或null</returns>
public T Single(Expression<Func<T, bool>> Expression)
{
return model.Set<T>().FirstOrDefault(Expression);
}
/// <summary>
/// 查询单个对象
/// </summary>
/// <param name=”id”>主键</param>
/// <returns>单个对象或null</returns>
public T Single(int id)
{
return model.Set<T>().Find(id);
}
/// <summary>
/// 添加
/// </summary>
/// <param name=”info”>数据</param>
/// <returns>受影响的行数</returns>
public int Insert(T info)
{
model.Set<T>().Add(info);
return model.SaveChanges();
}
/// <summary>
/// 删除
/// </summary>
/// <param name=”info”>数据</param>
/// <returns>受影响的行数</returns>
public int Delete(T info)
{
model.Set<T>().Remove(info);
return model.SaveChanges();
}
}


程序员灯塔
转载请注明原文链接:BaseDAL
喜欢 (0)