1

This is literally driving me nuts. I created a table, as you can see from the image below:

oracle table structure

And this is the fluent configuration for the User entity:

//this is the User entity model class
public class User
{
    public long Id { get; set; }
    public string EmailAddress { get; set; }
    public string HashedPassword { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int IsAdmin { get; set; }
}

public class UserEntityModelBuilder : IEntityModelBuilder
{
    public void Build(DbModelBuilder modelBuilder)
    {
        var config = modelBuilder.Entity<User>();

        config.Property(e => e.Id).HasColumnName("ID");
        config.Property(e => e.EmailAddress).HasColumnName("EMAIL");
        config.Property(e => e.HashedPassword).HasColumnName("PASSWORD");
        config.Property(e => e.FirstName).HasColumnName("NOME");
        config.Property(e => e.LastName).HasColumnName("COGNOME");
        config.Property(e => e.IsAdmin).HasColumnName("ADMIN");

        config.ToTable("UTENTIEROGAZIONE").HasKey(e => e.Id);
    }
}

Now I'm running a really simple LINQ statement just to test the login and it's throwing this weird exception message:

enter image description here

The fact is I'm using just VARCHAR2 fields, I can't understand what the hell is going on...any clues?

EDIT (added DbContext initialization):

public BarcodePrinterDbContext(IConnectionStringProvider connectionStringProvider, 
    IEnumerable<IEntityModelBuilder> entityModelBuilders) 
    : base(connectionStringProvider.GetConnectionString())
{
    _entityModelBuilders = entityModelBuilders ?? 
        throw new ArgumentNullException(nameof(entityModelBuilders));

    Database.SetInitializer(
        new NullDatabaseInitializer<BarcodePrinterDbContext>());
}

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    //setting the schema for Oracle DB
    SchemaSetup.SetupSchema(modelBuilder);

    //registering all entities fluent configurations on the model builder
    foreach (var entityModelBuilder in _entityModelBuilders)
        entityModelBuilder.Build(modelBuilder);

    /*
    * I googled out something on wrong mappings on string types, 
    * so I tried to set all string fields to a maximum of 2000 
    * characters, unfortunately with no success.
    */

    modelBuilder
        .Properties()
        .Where(p => p.PropertyType == typeof(string) &&
                    p.GetCustomAttributes(typeof(MaxLengthAttribute), false).Length == 0)
        .Configure(p => p.HasMaxLength(2000));
}
lucacelenza
  • 1,259
  • 1
  • 15
  • 28
  • Isn't EmailAddress a class. Don't you want emailAddress.EMAIL? – jdweng Feb 08 '19 at 11:29
  • @jdweng nope: EmailAddress is a string property and emailAddress is a string argument – lucacelenza Feb 08 '19 at 11:31
  • why do you use string.Equals? Does the same error occur if you switch it to == ? – DevilSuichiro Feb 08 '19 at 12:37
  • @DevilSuichiro yep, already tried still same exception – lucacelenza Feb 08 '19 at 12:40
  • Can you show us where you are initializing/setting-up your DbContext?? Have a look at these posts: [link 1](https://stackoverflow.com/questions/15750172/entity-framework-oracle-cannot-insert-varchar2-1-999-characters/17324250#17324250), [link 2](https://stackoverflow.com/questions/47168183/entity-framework-ora-00932-inconsistent-datatypes-expected-clob-got-char), [link 3](https://social.msdn.microsoft.com/Forums/en-US/8d764c44-33ed-4f08-91df-2ffb8a1f8a8d/ef-code-first-composite-key-a-linq-says-oracle-exception-ora00932?forum=adodotnetentityframework). – Sean Sailer Feb 08 '19 at 14:33
  • @SeanSailer I already checked similar posts and not one has been able to help: I wrote that modelBuilder code just so everyone would know I had already tried to contain every string property on my entities to a maximum of 2000 chars. DbContext initialization added, btw – lucacelenza Feb 08 '19 at 14:50

1 Answers1

1

FYI it was all about the target schema setting: I was injecting an old SchemaSetup object with a different schema instead of "IMPEGNATIVE". Unfortunately I was able to run the query over it 'cause I had all sorts of privileges set on the db user, thus the error (the table in this other schema actually had NCLOB fields).

So, always check your target schema!

lucacelenza
  • 1,259
  • 1
  • 15
  • 28