NHibernet Fundamentals
NHibernet Fundamentals
html
Add customer.hbm.xml
Add log property to get the query that generated behind the scenes
Add nihibdernet profiler from nuget manager
Then initialize
Insert data
Update the data
Nhibernate fundas and basic mapping an
persistence
Check for code and convention based too
To Save enum as string value
Then do below
If we want we can even rename above config file and pass it to the
Cfg.Configure(“FileName”);
Also provide connection string intwo ways – direct string or name of connection placed in
app.config
Show_sql is similar to ShoqSqlInConsole to see generated sql
Avoiding n+1 select means foreach order collections I need one specific line item
Fetch=join strategy gets the results intantaly of associated entity with outer join. By default
hibernet does 2 round trips one for main record then second when we access associated entity
Above is also doing same thing as mentioned – (eager load ) comes with associated entity
Many to one doesn’t have inverse property ad it always is set from that from the owned tem,from
the child item.
GET VS LOAD
Get fires call to database immediately while load does not need to access database immediately
and returns a proxy object when you issue that Load call -it can optimize database round trips.
If later in when you access that proxy, the object doesn’t happen to be in database – it can throw
an object not found the exception at that point.
And if you have akready called load on particular object then next time it will return actually
object instead of proxy as object is already loaded.
To perform query use hibernet query language
Aboce customer is class name and firstname is property name (not database table and field name)
Hql is very old and returns array (if we don’t cast as in above ) it will return array object
When you use queryhover – u need to use method chaining mix (conventional linq syntax wont
work) , and you can not mix xlassic cirteria and linq