zoukankan      html  css  js  c++  java
  • Proposed solution for the NHibernate exception “Column ‘Reserved Word’ does not belong to table ReservedWords.”

    原文 已被墙

    When I updated my NHibernate assembly to version 2.1.0.GA and tried to configure it against my MySQL installation with the .NET Connector v 5.2.7 I got an exception that I hadn’t encounter before:

    System.ArgumentException : Column ‘Reserved Word’ does not belong to table ReservedWords.

    After some searching and digging I found that this was a common problem when upgrading to the newer versions of the MySQL .NET Connectors and the cause seemed to be that the implementation of the DbConnection.GetSchema in the System.Data.Common namespace that is used when creating .NET connectors isn’t all that clear in MSDN and MySQL had changed their own implementation.

    This change caused the exception in NHibernate because in the MySQLMetaData.cs the column name is reference by a hard coded string and thus resulted in a miss match between the column names. Here is the code that caused the problem:

    public override ISet<string> GetReservedWords()
    {
    var result = new HashedSet<string>();
    DataTable dtReservedWords = Connection.GetSchema(DbMetaDataCollectionNames.ReservedWords);
    foreach (DataRow row in dtReservedWords.Rows)
    {
    result.Add(row["Reserved Word"].ToString());
    }
    return result;
    }

    Looking into how the MySQL team had implemented their connector and how NHibernate works and also searching through the documentation for the System.Data.Common namespace I propose a solution to this problem by using a similar approach as when calling the GetSchema with the static DbMetaDataCollectionNames.ReservedWords parameter and use the also static DbMetaDataColumnNames.ReservedWord when retrieving the reserved words column, resulting in the following:

    public override ISet<string> GetReservedWords()
    {
    var result = new HashedSet<string>();
    DataTable dtReservedWords = Connection.GetSchema(DbMetaDataCollectionNames.ReservedWords);

    foreach (DataRow row in dtReservedWords.Rows)
    {
    result.Add(row[DbMetaDataColumnNames.ReservedWord].ToString());
    }
    return result;
    }

    I have tested this solution against NHibernate 2.1.0.GA with the MySQL connectors 5.1.7, 5.2.7 and 6.0.4 and they seems to play nice with this update. See the issue here

  • 相关阅读:
    跨平台技术
    Unity和虚幻的比较
    商业模式(四):群硕软件,欧美客户为主的软件外包
    商业模式(四):群硕软件,欧美客户为主的软件外包
    Volley完全解析
    双十一京东图书购物清单,动动脑子节省300元
    双十一京东图书购物清单,动动脑子节省300元
    ListView异步加载图片,完美实现图文混排
    使用DrawerLayout实现QQ5.0侧拉菜单效果
    商业模式(三):P2P网贷平台,毛利润测算
  • 原文地址:https://www.cnblogs.com/philzhou/p/2523607.html
Copyright © 2011-2022 走看看