I've read in a lot of websites and particulary in oracle forums that Entity Framework Code First or DbContext API is NOT officially supported by Oracle.
That being said, I've also read in a lot of places that people have succesfully deployed projects using EF CodeFirst with Oracle. I've been running through a lot of issues and have been adjusting the code in order to make it work with SQL Server too.
One function that does not seem to work is DbSet.Find where you pass the key as parameter and gets exactly that record.
Using Find (which works just fine if I use sql server on the same codebase) throws an exception with the following error:
ORA-00942: table or view does not exist
I read this question about it and they mention casing, which is not my case so no fix for me.
The odd thing is that using DbSet.SingleOrDefault(x => x.Id == SomeId)
works just fine so I'm pretty sure the casing of the schema, table names and columns is fine.
Has anyone successfully used Find when using DbContext?
Please do note: I'm not using an EDMX and can't use it, we must continue using CodeFirst.
Thanks.
Well it turns out that there was indeed a problem with the data annotations made in my classes and I had a typo on one of them but the exception does not expose the referenced table or view so the only way to find out was to check that:
Corresponded to the table names
...for all of my classes that had a DbSet on my DbContext implementation.
Now, the reason why
DbSet.Find()
was throwing the exception andDbSet.SingleOrDefault()
was not is beyond my knowledge but I assume that the first traverses all of your POCO classes and tries to map them in the DbContext object even if the DbSet you are working on does not relate to the others on this same DbContext, on the other hand,SingleOrDefault()
does seem to check mappings for only those tables and objects you are actually going to use when querying.So yes, I assumed that since
DbSet.SingleOrDefault()
was not throwing and exception butDbSet.Find()
was, the problem was on EF and not on my mappings.Different extension methods have different behaviors so be careful and pay attention to those mappings!