linqvisual-studiolinq-to-sqlsqlmetal

how to force sqlmetal to keep field name case?


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 :-(


Solution

  • 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