How to force sqlmetal to keep a field name?

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

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

ses_Id -> Ses_Id
aga_Id -> Aga_Id

etc. - this probably changes camelCase to CamelCase.

No switch is specified in Sqlmetal help to save as-is field names (there is only a pluralize switch). So, does anyone know a hidden switch to keep the field name case insensitive?

Thanks in advance.

solvable

There is no such switch, and MS was notified of the problem - the report on the desire to add such a function (because it causes a problem with updating the project) was closed as wontfix: - (

+5
source share
1 answer

I doubt there is a hidden switch. I had the same problem, so I wrote a simple Perl script to figure 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 it all to fdbml.pl, make sure you have ActiveState Perl installed, and then run this in your DBML file:

fdbml.pl old.dbml new.dbml

Ben

+3
source

All Articles