Oracle to EF 6 mapping

51 Views Asked by At

I have the following code reading data from an oracle database.

public class IngredientModelContainer : DbContext
{
    public IngredientModelContainer() : base("OracleDbContext")
    {
    }

    public DbSet<Ingredient> Ingredients { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        Database.SetInitializer<IngredientModelContainer>(null);
        base.OnModelCreating(modelBuilder);
    }
}

[Table("LINE")]
public class Ingredient
{
    [Key]
    public int ID_NO { get; set; }
    public int BATCH_ID { get; set; }
    ....
}

I tried mapping the Ingredient class to a custom table name with the property, but it won't read anything and always returns 0 results:

_context.Ingredients 
        .Where(w => w.BATCH_ID == batch)
        .ToList();

I tested a manual SQL query however and it works

return _context.Ingredients
        .SqlQuery("Select * from LINE WHERE BATCH_ID = " + batch)
        .ToList<Ingredient>();

This works perfectly and returns exactly what I'm looking for so that proves the connection part. Is this a mapping issue between the class and table?

1

There are 1 best solutions below

0
On

Sorted it. Everything I did was correct - I was just missing the first part of the table name.

"xxx.LINE"