0

From what I have gathered. the DbSet is a typed entity cache, and on Save, a DbContext polls all DbSets for entities in need of persistence. In NHibernate, the caching and change detection for all entity types are combined in an ISession instance.

So, to convert very simple EF code to NH code, I can do away with the DbSet and just perform all operations straight on the session?

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
ProfK
  • 49,207
  • 121
  • 399
  • 775

1 Answers1

3

The only strongly-typed way to query entities in EF is using Linq. So each entity type has its own property of type DbSet<T> in the data context which implements IQueryable<T>.

In NHibernate, there are multiple query APIs (LINQ, QueryOver, Criteria [non-generic]) available and users are expected to use the ISession dynamically.

So instead of context.Companies.ToList() you can perform session.Query<Company>().ToList(), session.QueryOver<Company>().List() or session.Criteria(typeof(Company)).List().

The nice part about NHibernate is everything in that API is an interface, so there is no mocking involved unlike unit testing DbSet<T> instances.

Dmitry S.
  • 8,373
  • 2
  • 39
  • 49
  • I think I'll just build a little `NhSet` shim, that passes all calls such as `Add`, straight to the session. There are too many `DbSet` variables lying around. – ProfK Jan 06 '16 at 19:28