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?
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 implementsIQueryable<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 performsession.Query<Company>().ToList(),session.QueryOver<Company>().List()orsession.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.