Passing Autumn

The same 3 years, and some people from students to as the MVP, and I was in place, then the code to show off the autumn wind, a little sad, a little cool!

Bulletin
Content is very powerful ~ ~ ~ ~ ~ ~ Do not look outside the invasion not as sharp and brother, I felt kind of sense of loss ~ ~ ~

不支持泛型上下文绑定对象: ContextBoundObject与泛型类

刚刚打算折腾增加这么一个类来处理CYQ.Data的OrmBase里关于查询的泛型返回:


      /// <summary>
    /// ORM扩展基类
    /// </summary>
    [AopAttribute]
    public abstract class OrmBaseT<T> : OrmBase
    {
        /// <summary>
        /// 列表查询
        /// </summary>
        public new List<T> Select()
        {
            return base.Select().ToList<T>();
        }
        /// <summary>
        /// 列表查询
        /// </summary>
        /// <param name="where">查询条件[可附带 order by 语句]</param>
        /// <returns></returns>
        public new List<T> Select(string where)
        {
            return base.Select(where).ToList<T>();
        }
        /// <summary>
        /// 列表查询
        /// </summary>
        /// <param name="topN">查询几条</param>
        /// <param name="where">查询条件[可附带 order by 语句]</param>
        /// <returns></returns>
        public new List<T> Select(int topN, string where)
        {
            return base.Select(topN, where).ToList<T>();
        }
        public new List<T> Select(int pageIndex, int pageSize)
        {
            return base.Select(pageIndex, pageSize).ToList<T>();
        }
        public new List<T> Select(int pageIndex, int pageSize, string where)
        {
            return base.Select(pageIndex, pageSize, where).ToList<T>();
        }
        /// <summary>
        /// 带分布功能的选择[多条件查询,选择所有时只需把PageIndex/PageSize设置为0]
        /// </summary>
        /// <param name="pageIndex">第几页</param>
        /// <param name="pageSize">每页数量[为0时默认选择所有]</param>
        /// <param name="where"> 查询条件[可附带 order by 语句]</param>
        /// <param name="count">返回的记录总数</param>
        public MDataTable Select(int pageIndex, int pageSize, string where, out int count)
        {
            return base.Select(pageIndex, pageSize, where, out count);
        }
    }

OrmBase 类:

  /// <summary>
    /// ORM扩展基类
    /// </summary>
    [AopAttribute]
    public abstract class OrmBase : ContextBoundObject, IDisposable
    {
      ......省略
     }

一切想的很美好,编绎时正常,谁知运行时才出异常:不支持泛型上下文绑定对象


经过一番领悟,是"ContextBoundObject"不支持泛型类的原因,微软MSDN上有这样一段话:

对实施者的说明
公共语言运行库的当前版本不支持通用的ContextBoundObject类型或ContextBoundObject中的非泛型类型,泛型方法。 试图创建这样一个类型的一个实例,会导致TypeLoadException 。

既然知道了,接下来怎么迂回处理,还得想想。。。

Autumn Park is QBlog the official site, created by the passing autumn, based on the framework data layers developed cyqdata support multi-user, multi-language, multi-database (access, mssql, oracle), directory level url and other powerful blog system
新浪微博粉丝精灵,刷粉丝、刷评论、刷转发、企业商家微博营销必备工具"

2013/6/16 3:19:58 | Other | |

#2游客[注册][60.173.216.*]2016/2/17 15:06:28
lz,你 问题 现在 解决了吗?

我 也 在 定义ORM的时候,使用 了 你 的这个情况,悲剧了。

找 好久 ,才 发现 是派生了 泛型类导致 的问题,于是百度到 了 你 的 这个 博客。
#1游客[注册][120.199.21.*]2013/7/25 9:33:20
楼主 我也遇到这个问题 请问你有解决吗
reply没有解决方案,只能二者选一。
  • Post Comment