Example #1
0
        /// <summary>
        /// 获取上下文
        /// </summary>
        /// <returns></returns>
        public static DbContext GetContext(DbOpertionType OpertionType)
        {
            DbContextType ContextType = DBInitializer.DbContextType;

            if (ContextType == DbContextType.MySql)
            {
                if (OpertionType == DbOpertionType.Read)
                {
                    return(new ReadMySqlContext());
                }
                else
                {
                    return(new WriteMySqlContext());
                }
            }
            else
            {
                if (OpertionType == DbOpertionType.Read)
                {
                    return(new ReadSqlServiceContext());
                }
                else
                {
                    return(new WriteSqlServiceContext());
                }
            }
        }
Example #2
0
        /// <summary>
        /// 获取上下文操作
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="OpertionType"></param>
        /// <returns></returns>
        public static TEntity CallContext <TEntity>(DbOpertionType OpertionType) where TEntity : DbContext
        {
            var DbContext = GetContext(OpertionType);

            return((TEntity)DbContext);
        }