Nhibernate (and ORM in general): working with objects or objects?

This is what has been pulling me for a while. Consider a web application (MVC type) with ORM (e.g. Nhiberate) as the data access layer.

On the one hand, - the hand of the OOP / God domain model - I feel that I need to transfer (links to) the real objects that I'm talking about.

On the other hand , the DB / Web App team, I feel that it’s easier and more efficient to simply pass entire identifiers of objects, rather than the object itself.

Consider an e-commerce catalog type application:

  • The user logged in and went to the product page.
  • They post a comment.
  • The actions of the controller that are performed with saving this comment contain 3 parts of information: a) user identifier (from the auth cookie or elsewhere), b) product identifier (possibly from the query string) and c) comment text.
  • Now, what's the best thing here? Is it really worth inflating the user and product objects (for example, getting them from the repository with all the database work that entails) when we know that all they will use is that ORM can read its identifiers and set the corresponding foreign keys in the DB table in which the comments are stored?

? , - , , - ? , " ", , , - .

, , , , , , , ASP.NET MVC, .

.

+3
1

NHibernate ( get) .

session.Save(
  new Comment
      {
         Text = commentTextFromScreen,
         User = session.Load<User>(userID),
         Product = session.Load<Product>(productID)
      }
};

NHibernate: , , . NHibernate - , , - .

Ayende: Get, Load id.

+3

Source: https://habr.com/ru/post/1757104/


All Articles