【问题标题】:Proper way to transform column and table names in SubSonic 3在 SubSonic 3 中转换列名和表名的正确方法
【发布时间】:2010-08-07 06:41:19
【问题描述】:

我正在尝试使用 ActiveRecord 模板将名为 app_user 的表转换为 SubSonic3 中的 AppUser.CreatedDt,该表具有名为 created_dt 的列。从我所见,应该能够在 Settings.ttinclude 的 CleanUp 方法中根据需要修改表名和列名

所以我在 Settings.ttinclude 中添加了这个方法

string UnderscoreToCamelCase(string input)  {

        if( !input.Contains("_"))
            return input;

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < input.Length; i++)
        {
            if (input[i] == '_')
            {
                while (i < input.Length && input[i] == '_')
                    i++;
                if (i < input.Length)
                    sb.Append(input[i].ToString().ToUpper());
            }
            else
            {
                if (sb.Length == 0)
                    sb.Append(input[i].ToString().ToUpper());
                else
                    sb.Append(input[i]);
            }
        }

        return sb.ToString();
    }

然后是对 CleanUp 的调用

result=UnderscoreToCamelCase(result);

如果我运行如下查询:

var count = (from u in AppUser.All()
             where u.CreatedDt >= DateTime.Parse("1/1/2009 0:0:0")
             select u).Count();

我收到 NotSupportedException,不支持成员“CreatedDt”

来自 TSqlFormatter.sql 第 152 行中的一个方法

protected override Expression VisitMemberAccess(MemberExpression m)

如果我注释掉对 UnderscoreToCamelCase 的调用并使用数据库中的名称,一切正常。

一件有趣的事情是,当一切正常时,永远不会调用 VisitMemberAccess 方法。

有没有其他人能够在 SubSonic3 中将带有下划线的表/列名转换为驼峰式?

【问题讨论】:

    标签: subsonic subsonic3


    【解决方案1】:

    在 StackOverflow 的另一个线程上可能会有答案,但它需要修改 Subsonic.core 的源代码。 link text

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多