Best approach for building NHibernate DTO's

后端 未结 4 1874
夕颜
夕颜 2021-01-03 03:16

I\'m new to NHibernate (and ORMS) and trying to come to grips with the myriad of different options it presents. For reference, I\'m using Fluent NHibernate with seperate bus

4条回答
  •  猫巷女王i
    2021-01-03 03:50

    In general, DTOs do not contain behavior (like Save, Load) and do not contain knowledge of how they get persisted (ISession). It sounds like what you are really creating is a data layer. Your business layer ideally shouldn't know about ISession either. That said, you can shortcut this layering all you want as it fits your needs, but it will likely be difficult to change to a different ORM later if your ORM bleeds through all your layers.

    For ISession lifetime management, you have to decide if you are going to use the UnitOfWork pattern, which basically says every user request gets a new ISession. There are other options for ISession lifetime as well and you really aren't limited in that regard. Often, there may be best practices around web apps vs. windows apps vs. whatever other application types, but you didn't specify which you were writing.

提交回复
热议问题