Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [orm]

Object-relational mapping (ORM) is a technique for mapping between object-oriented systems and relational databases.

0
votes
1answer
79 views

Private class in ORM Repository?

Is this a code smell? I have a repository which connects to a SQL server. This repository uses Dapper to map the results to an object. I have a method in this repository that checks a result, then ...
1
vote
1answer
65 views

How to handle a many to many relationship with an ORM mapped to a Domain Model when there are no technical constraints?

Domain Driven Design states that you should have a domain model, which reflects the ubiquitious language used by the domain experts. When using ORMs and many to many relationships I am use to doing ...
1
vote
2answers
142 views

Encapsulation and input validation duplication

Consider the following example (very simplified): public class Basket { private readonly List<BasketItem> _items = new List<BasketItem>(); public IReadOnlyCollection<BasketItem&...
2
votes
1answer
132 views

How should I design a 3-tier-architecture application with Entity Framework?

This is almost getting me crazy. EF bring us a very convenience experience in development. However, if we need to use the Entity model in the upper layer, we always put a reference from the upper ...
-1
votes
1answer
50 views

Calculating time an object stays in a state

I use Python sqlalchemy to store my model in a MySql database. One of my objects has a 'state' field (for simplicity let's assume there are two states: AVAILABLE and UNAVAILABLE). There are ...
1
vote
2answers
116 views

When using an ORM when should I sacrifice performance for convenience?

I work with SQL Alchemy a lot and, as a "lazy programmer", I enjoy the convenience it offers. But the "diligent programmer" in me often worries about optimisation and the performance of the queries ...
3
votes
2answers
129 views

Separating Domain Object and Data Models

I looked through a lot of articles, blogs, and SO topics about separating domain object and data models. Almost every answer said: You should have separate classes for the domain and data persistence, ...
26
votes
5answers
7k views

Should I check if something exists in the db and fail fast or wait for db exception

Having two classes: public class Parent { public int Id { get; set; } public int ChildId { get; set; } } public class Child { ... } When assigning ChildId to Parent should I check first if ...
1
vote
0answers
159 views

Handling complex dynamic queries in Laravel 5

I am developing a project using Laravel. My workflow is: route directs to controller Controller calls eloquent models Eloquent models perform queries (tipically CRUD and find) Controller returns ...
1
vote
1answer
150 views

Entities and polymorphic relationships

Lets say that I have a shelf on which I can put items that are shelfable (not sure if that is actually a word but you can understand my point). So I have the following: class Shelf { /** @var ...
1
vote
4answers
92 views

How do I approach structuring when to read/write objects to db?

This is a problem I've faced in many languages over the years (js, go, c, f#, haskell, python, ...), but I haven't found a general approach to solving this yet. Learning about consistency models in ...
-1
votes
1answer
281 views

ORM vs Web API differences

I'm struggling to understand the differences between an API such as a REST API and an ORM such as Entity Framework. I would also like to understand the benefits of each and in what situations either ...
1
vote
1answer
90 views

How can I model unknown and an unknown number of attributes on an object?

My example might be slightly contrived, because I've modified it so that the project isn't recognizable by my employer. I'm a newer developer at a very small company. We have an object - Posts - that ...
0
votes
2answers
72 views

Best practice for object relation mapping to execute delete/update

In doctrine (or any ORM in general), the easiest way to execute a delete/update operation is to select such entity, then remove entity or update single attribute in the code, ended by persist the ...
0
votes
1answer
200 views

Data Mapper Pattern and DDD - Does ist already reflect domain entities and repositories?

I'm getting used to DDD so don't assume I'm a DDD pro yet. I'm trying to implement a hexagonal architecture using the CakePHP framework in a completely custom made application that just utilizes the ...
2
votes
1answer
44 views

Should the ORM create the related objects (ForeignKey objects) when saving the entity?

This question is coming from a frustration when using the Entity Framework and ASP.NET MVC, but I assume it's a general frustration across more frameworks and languages. Lets say we have an object ...
5
votes
1answer
140 views

Split ORM module without creating cyclic imports or side-effects

Preface I have an ORM library for a relational real estate database. The used framework is peewee. The library contains ~60 models, each representing a distinct table. The models represent a (pre-...
1
vote
1answer
113 views

ORM for 600 tables

I am working on a huge application in php which contains almost 600 tables to work with, not to mention it requires complex joining for 10 or 15 tables together. i wanted to ask how much ORM is good ...
3
votes
1answer
105 views

Database modeling. Many to Many relationships. Link tables

Consider a database table for user info like: id, name, email now consider I have another table for video something like: id, name, description, length Say a many to many relationship exists ...
2
votes
1answer
34 views

Advice on AggregateRoot boundaries

I am confused on how to apply DDD principles for the design of domain entity clusters with Aggregate Root. According to my understanding, Aggregate Root enforces business validations and all entities ...
4
votes
1answer
247 views

Routing all SQL queries through a single micro-service

I currently have a website, made of about 20 micro-services and a (still too large) main monolithic web application. The monolith and multiple micro-services each run queries to the same database, ...
0
votes
2answers
360 views

Ways to store objects, inherited from one superclass in a database

For my personal project I need to store 2D shapes in a Postgres database. For example Circle, Pentagon, Rectangle and so on. At first I've done it like so: all shapes are inherited from an abstract ...
-2
votes
1answer
73 views

Is generating Hibernate Entities from database tables considered a bad practices?

On my current project it is a common practice to generate Hibernate Entities from database tables using NetBeans functionality. I'm normally used to first write the Entity-class and define the mapping ...
1
vote
1answer
125 views

Is there a better design than reflection to deal with large numbers of ORM objects?

Here's a scenario I've encountered variations of on many occasions. Imagine an XML feed which displays data about three different types of event: concerts, plays and movies. Each has a different set ...
2
votes
2answers
111 views

Object that can set its own subclass/amend its methods with subclass?

I have a database that stores client data. All data is in one table. For each client, there is one row per day. Clients have different kinds of contracts, their data format remains the same, however, ...
3
votes
1answer
197 views

Data access design pattern

I've several cases where a single entity has multiple tables in the underlying database. When reading or writing I want to handle all of the DB queries with a single class for that object, e.g., the ...
0
votes
2answers
179 views

Where should I put the database access method in a treeview environment

I have written a class to represent 'Treeview-like' data, which can be simplified as: public class Item { public string Name { get; set; } public KPI AssociatedKPI { get; set; } public ...
2
votes
1answer
1k views

Table Per Concrete Type in Entity Framework Core

I'm trying to port code from entity framework 6 (EF6) to entity framework core 2.0 (EF-Core) and have ran into a dead end. In my EF6 code, I have a base class called Record which defines the base ...
1
vote
1answer
867 views

Service layer with DTO

I'm refactoring my desing to use a service layer - however I'm confused about how you would pass arguments, when it's only allowed to update certain fields of the entity. For instance I have some ...
0
votes
4answers
249 views

The Open/Closed Principle, how does it work for adding entities?

I'm not even sure how to ask this, but here goes: Let's say I have a Web application that incorporates Teachers, Courses and Students in such a way that I can do things like this (pseudocode): ...
2
votes
2answers
531 views

Object To Be Used By Service Layer

My project has a UI layer, a Service Layer and a Repository layer. The latter has Entity objects as part of the ORM (.net Entity Framework). The service later returns a Dto to the UI layer. My ...
-3
votes
1answer
52 views

Dynamic query building for report generation tool : suggestion for better approach

I have a requirement for a reporting tool in which the user will be selecting the "class" that has some associated column and "filter" option in the view. Each class is associated with a list of ...
0
votes
1answer
88 views

Dry refactoring against database

Our database has an Attribute table and a WorkItem table that are in a many to many relationship using a WorkItemAttribute table. The WorkItemAttribute table contains the foreign keys for each and a ...
0
votes
2answers
57 views

Class For Summarised List Of Complex Objects

Assume I have a class that represents a complex domain object with dozens of properties, such as a pension policy. The GUI lists all pensions in a summary table that only contains a small subset of ...
11
votes
8answers
3k views

Unifying programming and database query [closed]

Consider a common tutorial for object-oriented programming languages like C++ or Java: create a simple order processing system with objects representing accounts, orders, items etc (or something more ...
0
votes
1answer
634 views

Using Laravel with DAO instead of Eloquent ORM

We have a complicated ERP software written in native PHP and our own micro-framework which uses big and complicated queries. We want to rewrite the application using an MVC framework (e.g. Laravel). ...
5
votes
3answers
454 views

Stored procedures or ORM in web?

I am working in a Peruvian company that develops desktop accounting software(.net C#). We have many clients (companies) each customer can create several companies, in addition there is a new database ...
3
votes
3answers
691 views

Role based Database Schema

I am designing a database for a document management app for my office. I want to get the backend right so I don’t have issues in the future. Basically all users will be categorized into roles e.g, ...
1
vote
1answer
578 views

ORM Inheritance mapping or not, how to map shared and specific properties for a set of related, real world objects

When I was starting in OO programming, mostly Symfony and Doctrine ORM, I have been advised at least one time to apply inheritance mapping for a case as follows: For instance, a HR system which deals ...
1
vote
3answers
525 views

Organisation of complex business-logic (set of rules)

I have 20 entities and 50 user requests. And i have very complex business-logic (set of rules). How can i make my architecture so I'm not confused when adding new rules. Now if i add property "...
3
votes
2answers
112 views

Beste practice: ORM (in PHP, but general): Save changes to database directly or on request?

Imagine an ORM system, independent of language but let's assume PHP. Data is encapsulated in PHP objects and stored into and loaded from database. Let us have a theoretical object "Person" with ...
1
vote
1answer
286 views

Doubt about representing a Shopping Cart in Class Diagram/ER Database implicating ORM

I have to do a task which is reading a text, and create a Class diagram. One of the entities is a Shopping Cart. My doubt is how to represent a Shopping Cart in a class diagram, later on an E/R ...
8
votes
3answers
2k views

Is ORM a bad tool for tree-like DB structures?

I know this question might be closed as opinion-based, but what I need right now are some opinions supported by arguments. I am building an application with Postgres and Ecto (Elixir) as the ...
1
vote
1answer
605 views

How to pass complex ORM objects to background workers?

I've been wondering something about how we pass complex ORM objects to background workers — in my case, Django models and Celery, but this could apply to any similar background processing framework. ...
1
vote
2answers
210 views

How should an ORM handle unassigned Id property?

Consider an ORM that maps tables to classes, and columns to properties. How should it handle a property that maps to an identity column for non-inserted objects? For example, [Table("MyTable")] ...
3
votes
2answers
116 views

Problem related to optimistic locking performance

I'm designing a system that like the majority of social related application has posts, people can like the posts and comment on them. And also like the majority of the applications the users can see ...
1
vote
1answer
146 views

Algorithm suggestions for handling CRUD Soft Deletes for delete and restore with multiple owning models

I have an active record based ORM with soft deletes (Laravel Eloquent to be specific) in an SQL database. The 'soft delete' behavior that is built in to the ORM is: If the record is not deleted, then ...
5
votes
1answer
193 views

Should I retrieve related entities from the parent entity or the service layer?

Let's say I have a three tier application structure, with Presentation, Service and Data layers. The data layer is managed by an ORM and has two models/entities, Show and Episode, with a one-to-many ...
1
vote
1answer
87 views

Why Entity framework default behavior is diconnected

I have read about connected model and disconnected model in the main ORM of Microsoft EF . And found that the default behavior is the disconnected . Then i read about the relationship between these ...
2
votes
1answer
113 views

How to make associations security proof

When designing an application I usually stumble upon a problem I've never quite managed to handle properly. Suppose you have Products and Orders. Usually in my data-access layer I have repositories ...