0

I would like Entity Framework v6 to not use quotes around identifiers when executing transactions against the database. Is it possible to configure the DbContext to do this without creating a configuration file for every entity?

For example:

Instead of

SELECT "ApplicationId"
FROM "dbo"."Applications";

I want

SELECT ApplicationId
FROM dbo.Applications;

Will Entity Framework be able to correctly map properties and entities to the database fields and tables correctly?

EDIT:

Rather than try to eliminate the quotation marks, I should have indicated that my goal is to interface with an Oracle DB. Oracle will require using quotation marks around identifiers that contain lowercase letters. So, I should probably change my request to indicate that I need all uppercase identifiers.

I came up with part of a solution in the OnModelCreating method of the DbContext, but it won't handle Foreign Key identifiers:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Properties()
           .Configure(c => c.HasColumnName(c.ClrPropertyInfo.Name.ToUpperInvariant()));
        modelBuilder.Types()
           .Configure(c => c.ToTable(c.ClrType.Name.ToUpperInvariant()));            
    }
youzer
  • 493
  • 4
  • 11
  • I believe it's not possible... or at least there's not a straightforward approach to accomplish this. Why you want this? Your question doesn't make sense to me – Fabio Jul 08 '15 at 17:56
  • @FabioLuz I restated my requirements with a partial solution. – youzer Jul 08 '15 at 18:33

1 Answers1

0

You can put the foreign key properties in your class, and then map their database column. Like this How to configure DbContext to work with Oracle ODP.Net and EF CodeFirst?

Or, if you don't want to put the foreign key property in the classes, you should use the fluent API to map the foreign key using uppercase letters. Like this example:

modelBuilder.Entity<Course>() 
    .HasRequired(c => c.Department) 
    .WithMany(t => t.Courses) 
    .Map(m => m.MapKey("CHANGEDDEPARTMENTID"));
Community
  • 1
  • 1
Fabio
  • 11,892
  • 1
  • 25
  • 41