EF Code First and capitalization

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
gavilanch
Posts: 2
Joined: Mon 15 Jun 2015 20:20

EF Code First and capitalization

Post by gavilanch » Mon 15 Jun 2015 20:30

Hello,

I have been having a problem when using code first for talking to an oracle database. The problem is that I would like to use non capitalized properties/tables, but I keep getting exceptions when I try it. Here is an example of an entity:

[Table("DEPARTMENTS2")]
public partial class Departments2
{
[Column("ID")]
public int Id { get; set; }

[Required]
[StringLength(50)]
[Column("DESCRIPTION")]
public string Description { get; set; }
}

Please notice that I have to change via annotations the capitalization of the name of tables and fields, otherwise I get an exception like "table or view not found" when trying to query the table Departments2 from EF. Is it mandatory to do it like this or there is a solution to my problem?

Thanks.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EF Code First and capitalization

Post by Shalex » Tue 16 Jun 2015 11:25

gavilanch wrote:I would like to use non capitalized properties/tables
Please run the following code with a clean schema:

Code: Select all

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            // http://www.devart.com/dotconnect/oracle/docs/?dbmonitor.html
            var monitor = new Devart.Data.Oracle.OracleMonitor() { IsActive = true };

            using (var context = new MyDbContext())
            {
                context.Database.Initialize(false);
            }
        }
    }

    class MyDbContext : DbContext
    {
        DbSet<Departments2> depts { get; set; }
    }

    [Table("Departments2")]
    public partial class Departments2
    {
        [Column("ID")]
        public int Id { get; set; }

        [Required]
        [StringLength(50)]
        [Column("Description")]
        public string Description { get; set; }
    }
}
It will create the following table:

Code: Select all

CREATE TABLE "Departments2" ( 
  ID NUMBER(10) NOT NULL,
  "Description" NVARCHAR2(50) NOT NULL,
  CONSTRAINT "PK_Departments2" PRIMARY KEY (ID)
)
Is that what you need?

If this doesn't help, please send us a small complete test project for reproducing the issue you have encountered.

gavilanch
Posts: 2
Joined: Mon 15 Jun 2015 20:20

Re: EF Code First and capitalization

Post by gavilanch » Wed 17 Jun 2015 16:26

I am sorry, it seems I did not make myself clear. Either way I solved my problem.

For future reference, my problem was that when I was making queries (SELECT), to the database (using Entity Framework), I was getting errors like "table or view does not exist", the reason for this is that the dot connect oracle provider was generating queries with quotations around identifiers (table names and column names). It turns out that I was able to turn off those quotations by using:

Code: Select all

  Devart.Data.Oracle.Entity.Configuration.OracleEntityProviderConfig config = Devart.Data.Oracle.Entity.Configuration.OracleEntityProviderConfig.Instance;
            config.Workarounds.DisableQuoting = true;  
Thanks for the service, and great tools you guys have!

Post Reply