/// <summary> /// 创建ef的dbSet /// </summary> /// <typeparam name="TEntity"></typeparam> /// <returns></returns> public DbSet <TEntity> CreateSet(DbConfig config, DbMode mode) { var dbContext = _contextFactory.Create(_dbFactory.GetDbInitContext(typeof(TEntity), mode, config)); if (!_dbContexts.Contains(dbContext) && mode.HasFlag(DbMode.Write)) { _dbContexts.Add(dbContext); } return(dbContext.Set <TEntity>()); }
/// <summary> /// 可以同事读写 /// </summary> /// <param name="mode"></param> /// <returns></returns> public static bool IsReadAndWrite(this DbMode mode) { return(mode.HasFlag(DbMode.Read) && mode.HasFlag(DbMode.Write)); }
/// <summary> /// 可以写,对读无限制 /// </summary> /// <param name="mode"></param> /// <returns></returns> public static bool CanWrite(this DbMode mode) { return(mode.HasFlag(DbMode.Write)); }
/// <summary> /// 只写入 /// </summary> /// <param name="mode"></param> /// <returns></returns> public static bool IsWriteOnly(this DbMode mode) { return(mode.HasFlag(DbMode.Write) && !mode.HasFlag(DbMode.Read)); }
/// <summary> /// 可以读,对写入无限制 /// </summary> /// <param name="mode"></param> /// <returns></returns> public static bool CanRead(this DbMode mode) { return(mode.HasFlag(DbMode.Read)); }