GMS.Framework.DAL/DbContextBase.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Linq;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq.Expressions;
using System.Data;
using System.ComponentModel.DataAnnotations.Schema;
using GMS.Framework.Contract;
using System.Threading.Tasks;
namespace GMS.Framework.DAL
{
/// <summary>
/// DAL基类,实现Repository通用泛型数据访问模式
/// </summary>
public class DbContextBase : DbContext, IDataRepository, IDisposable
{
public DbContextBase(string connectionString)
{
//var objectContext = (this as IObjectContextAdapter).ObjectContext;
//objectContext.CommandTimeout = 500;
this.Database.Connection.ConnectionString = connectionString;
this.Configuration.LazyLoadingEnabled = false;
this.Configuration.ProxyCreationEnabled = false;
}
public DbContextBase(string connectionString, IAuditable auditLogger)
: this(connectionString)
{
this.AuditLogger = auditLogger;
}
public IAuditable AuditLogger { get; set; }
public T Update<T>(T entity) where T : ModelBase
{
var set = this.Set<T>();
set.Attach(entity);
this.Entry<T>(entity).State = EntityState.Modified;
this.SaveChanges();
return entity;
}
public T Insert<T>(T entity) where T : ModelBase
{
this.Set<T>().Add(entity);
this.SaveChanges();
return entity;
}
public void Delete<T>(T entity) where T : ModelBase
{
this.Entry<T>(entity).State = EntityState.Deleted;
this.SaveChanges();
}
public T Find<T>(params object[] keyValues) where T : ModelBase
{
后面还有 52 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
