如何强制 sqlmetal 保持字段名称大小写?

发布于 2024-08-16 21:54:24 字数 413 浏览 6 评论 0原文

当 Visual Studio 自动生成 dbml 文件时,我得到了表中出现的确切字段名称。

但是,由于VS不提供dbml的刷新功能,因此我手动运行sqlmetal来重新创建dbml文件。它工作得很好,但有一个例外——sqlmetal“更正”名称

ses_Id -> Ses_Id
aga_Id -> Aga_Id

等等——它可能会将camelCase更改为CamelCase。

Sqlmetal 帮助没有列出任何保持字段名称不变的开关(只有复数开关)。那么,有谁知道保持字段名称大小写的隐藏开关吗?

先感谢您。

已解决

没有这样的开关,并且 MS 收到了有关该问题的通知 - 添加此类功能的愿望报告(因为它会导致更新项目出现问题)已被关闭,因为不会修复:-(

When dbml file is generated automatically by Visual Studio I get the exact field names as they appeared in the tables.

However, since VS does not provide refresh function for dbml, I run sqlmetal manually to re-create dbml file. It works fine with one exception -- sqlmetal "corrects" the names

ses_Id -> Ses_Id
aga_Id -> Aga_Id

and so on -- it probably changes camelCase to CamelCase.

Sqlmetal help does not list any switch to keep field names as-is (there is only pluralize switch). So, does anyone know the hidden switch to keep the case of field name?

Thank you in advance.

SOLVED

There is no such switch, and MS was notified about the problem -- the wish report to add such feature (because it casuses problem with updating project) was closed as wontfix :-(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云裳 2024-08-23 21:54:25

我怀疑是不是有隐藏开关。我遇到了同样的问题,所以我编写了一个简单的 Perl 脚本来解决它:

# Usage: fdbml.pl in.dbml out.dbml
my $in_file = $ARGV[0];
my $out_file = $ARGV[1];

# Scrape in file for identifiers
my @identifiers;
open IN, "<$in_file";
while (<IN>) {
    if ($_ =~ /<Table Name="(?:\w+\.)?(\w+)" Member="(\w+)"/) { push @identifiers, "$1 $2"; }
    if ($_ =~ /<Function Name="(?:\w+\.)?(\w+)" Method="(\w+)"/) { push @identifiers, "$1 $2"; }
}
close IN;

# Translate in file to out file
open IN, "<$in_file";
open OUT, ">$out_file";
while (<IN>) {
    my $line = $_;

    # Replace identifiers
    foreach my $identifier (@identifiers) { 
        my ($new, $old) = split(' ', $identifier);
        $line =~ s/"$old((?:Result)?)"/"$new$1"/g;
    }   
    $line =~ s/<Parameter Name="(\w+)" Parameter="\w+"/<Parameter Name="$1" Parameter="$1"/;

    print OUT $line;
}
close OUT;
close IN;

只需将所有内容保存到 fdbml.pl,确保安装了 ActiveState Perl,然后在 DBML 文件上运行它:

fdbml.pl old.dbml new.dbml

Ben

I doubt there is a hidden switch. I had the same problem, so I wrote a simple Perl script to sort it out:

# Usage: fdbml.pl in.dbml out.dbml
my $in_file = $ARGV[0];
my $out_file = $ARGV[1];

# Scrape in file for identifiers
my @identifiers;
open IN, "<$in_file";
while (<IN>) {
    if ($_ =~ /<Table Name="(?:\w+\.)?(\w+)" Member="(\w+)"/) { push @identifiers, "$1 $2"; }
    if ($_ =~ /<Function Name="(?:\w+\.)?(\w+)" Method="(\w+)"/) { push @identifiers, "$1 $2"; }
}
close IN;

# Translate in file to out file
open IN, "<$in_file";
open OUT, ">$out_file";
while (<IN>) {
    my $line = $_;

    # Replace identifiers
    foreach my $identifier (@identifiers) { 
        my ($new, $old) = split(' ', $identifier);
        $line =~ s/"$old((?:Result)?)"/"$new$1"/g;
    }   
    $line =~ s/<Parameter Name="(\w+)" Parameter="\w+"/<Parameter Name="$1" Parameter="$1"/;

    print OUT $line;
}
close OUT;
close IN;

Just save all that to fdbml.pl, make sure you have ActiveState Perl installed, then run this on your DBML file:

fdbml.pl old.dbml new.dbml

Ben

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文