Very strange issue with EF6. I have a DbSet<T> property defined on the context. Let's just say T is Entity, so it looks like this:
public virtual DbSet<Entity> Entities { get; set; }
If I say Entities.Count(), I get back a non-zero result. In this case, 504. However, here's where it gets strange:
var entity = context.Entities.First()
entity is null! When I log the underlying query, it looks absolutely fine. If I execute this query directly on the underlying database (which happens to be PostgreSQL, not SQL Server), it returns the right data.
I should also add that there are a large number of other models (over 40 of them), and they work just fine. Only this one does not.
The model itself is just a POCO with the usual virtual properties defined, e.g.,
class Entity {
public virtual string Property1 { get; set; }
}
And so on. Nothing special.
Why do I get a non-zero count (which is accurate), but the entities themselves are always null?