Is it better to have a single query that returns all related entities, or separate queries for each case?


Summary

When writing methods to query for related entities, is it better to have a single method for all related entities or separate methods for each combination?

Full Problem

I’m writing repository classes for a .NET MVC project where each repository is responsible for querying for a specific entity type. I’m using Dapper, so all of the queries are written by hand. The repositories all implement an IRepository<TEntity> interface, which has method TEntity FindById(id).

Fetching just the entity is obviously very straightforward, but I’m faced with a dilemma when it comes to fetching the entity’s children and grandchildren and so forth. Often times, for an entity to be usable, it needs some or all of its descendants. I initially wrote FindById to return the entity with all descendants, which satisfies all use cases, but is also wasteful in many where I only need several descendants.

I wrote out individual methods for fetching various combinations. FindByIdWithChildA or FindByIdWithChildBAndGrandChildC and such. The problem here is that the method names keep getting longer and longer, which makes them a pain to read, and also wastes a lot of space in code.

My next idea was to accept various enum flag values designating which descendants to return. This worked fine for the immediate children, but by the time I got to grandchildren and beyond I had so many possible combinations to implement, and many of them didn’t make sense or wouldn’t be used.

By the time I have all this boilerplate written out, it almost feels like I’m writing a bad ORM instead of repositories. This has certainly slowed down development dramatically, and it has taken focus away from actually implementing new features.

The obvious wrong solution is to not use SQL joins and have the repositories splice together entities and collections of entities using LINQ. Using LINQ with EntityFramework could be an option, but I don’t think that the solution is to switch to another library.

Should I just simplify and have the single method/query return everything? If not, what is the best way to concisely implement separate methods?

This answer indicated that a FindByIdWithChild type method is normal, but I can’t imagine that being good practice for complex queries.

Clarification

So my entities are Sport, Division, SkillLevel, and TeamType. Each Sport has a list of Divisions, SkillLevels, and TeamTypes. Each Division has a single TeamType and a list of SkillLevels.

Suppose I want a Division with its parent Sport, its TeamType, and all of its SkillLevels. Should I do:

  1. DivisionRepository.FindById(id) which returns all of these properties, ignoring any case where I want just a Division or a Division and Sport, Division and TeamType, etc.

  2. DivisionRepository.FindById(id, BitFlagQueryScope) which has a big mess of an implementation to resolve all the possible flags, some of which might not be needed.

  3. DivisionRepository.FindByIdWithSportAndTeamTypeAndSkillLevels(id) and have one of these methods for every combination I need.

In all three cases, I am making one trip to the database. It’s just a matter of how I structure my code.

Additional example, suppose I want a Sport with just its TeamTypes. Elsewhere I will need a Sport with its SkillLevels, etc. Same questions as above. I’m only making one database trip, but should I use different code for these different queries, or just grab everything and discard/not use the excess?

Additional Clarification

In case there’s something wrong with my design overall, here’s how I’m using the entities:

Action(string id) {     var sport = SportRepository.FindById(id); // This needs to either return everything associated with the entity or be changed to allow specification     var model = new SportDisplayModel(sport);     return View(model); } 

I have two models, $ Entity$ DisplayModel, and $ Entity$ EditModel, and I use them for every view.

In a DDD CQRS API, is it preferable to have a separate DTO per query or per representation of a resource?

I am in the middle of starting up a new project and just wanted some reassurance as to which approach to DTO’s returned by the read-side was easier to maintain in a real world application with reasonable complexity.

I realize with a DTO per query, it would allow for a specific query’s response to diverge from the others more easily in the future. However, common properties between that query and other queries would require changes in multiple places (e.g. the same resource could have multiple queries in the form of GetById, GetAll, GetByStatus, GetBySomethingElse, etc.) and there is more repetition.

If a DTO is created per representation of a resource, a GetById might return a DetailedDto with many properties, while a GetAll might return a SummarizedDto with fewer properties. This would require less changes for common properties and diverging queries would just require a new version of the DTO to be created. The biggest disadvantage to this approach is that I’m terrible at naming classes and coming up with words, so “Detailed” + “Summarized” is the extent of my imagination.

I’m leaning towards refactoring my first attempt at writing this application from using the “DTO per query” to the “DTO per representation” approach. Are there any benefits to sticking with the “DTO per query” or is “DTO per representation” a good way to go?

Extract document name and store them in separate document library columns

I have been tasked to extract the document name and store them in 4 separate columns in SharePoint. The new documents which are .PDF’s are named as such : Sam; Smith; 123456; Dental

And the column names on the list after stripping the document name are like below.

*FName: Sam
*LName:Smith
*Employee number: 123456
*Record Type:Dental
enter image description here
So, I have created the document library list and added the above 4 columns to document library. From link 2 I understand that a workflow using MS Flow is a possible solution but the example they deal with has just one “-” and the documents i am dealing with has two “;”. So i am really not sure how to come up with the sub-string expressions that they talk about.

Thank you for all your help and feedback.
Sam

How to go about combining separate codebases [on hold]

I joined a company and essentially am taking over the project entirely. However, they (a third party company) built our codebase. The codebase is split into two, a Javascript frontend that connects to a ruby on rails backend API.

I want to combine these codebases into one for ease of install, deployment, management, etc. However, I am not entirely sure how to go about this. It could definitely be my lack of understanding as I have only really dealt with combined codebases in the past (albeit one exception where I only worked on the back end of a codebase as a junior dev).

Does anyone have any history with a task like this?

How to separate out the displaying of logs in the terminal from the logging data

I am trying to jump back into logging and it’s been a while. From what I remember, in the past I’ve logged things as JSON and saved it to a file or larger distributed system, and it was processed into the db and such async. But what I don’t recall is how it goes from the log call in the source code to the display on the terminal, like when you tail the Heroku logs in a Rails app.

enter image description here

The question is how you generally display the logs in the terminal while keeping them separate as raw data/json for the backend to process. Is there a stdout log that is also recording what is written to the terminal (stdout)? Are we instead reading from that file to get our backend logs? Or do we not have a log file for stdout and instead just do 2 things: (1) write to stdout without logs on it, and (2) write our JSON to our log server.

Wondering generally how it’s done.

I ask because I would like to display a better more pretty version of the logs in the terminal, yet still keep them as JSON data in the backend.

add dot to each line based on a separate column using ggplot2 + linerange()

I have a linerange graph that shows sightings of birds and their diet over time.

Using the below example I would like to add a further layer, using a column entitled time_period, which has grouped the data into 3 levels: <10 years, 10-20 years, >20 years. However, I’ve come stuck. I would like to:

  1. Add a little coloured dot next to each line based on the time_period column
  2. Add a legend underneath that shows what each dot means

The dataset is taken from this csv file here, and looks like this:

head(bird_models_traits) # A tibble: 6 x 17   decimal.latitude decimal.longitu~ class species.name id    duration minyear maxyear system              <dbl>            <dbl> <chr> <chr>        <fct>    <dbl>   <dbl>   <dbl> <chr>  1            -54.6             159. Aves  Aptenodytes~ 2283        10    1970    1980 Marine 2            -43.0             147. Aves  Larus domin~ 8990        28    1980    2008 Marine 3            -43.0             147. Aves  Larus novae~ 8992        25    1983    2008 Marine 4            -43.0             147. Aves  Larus pacif~ 8991        28    1980    2008 Marine 5            -42.9             147. Aves  Calidris fe~ 8940        33    1974    2007 Fresh~ 6            -42.9             147. Aves  Calidris ru~ 8942        34    1974    2008 Fresh~ # ... with 8 more variables: common.name <chr>, estimate <dbl>, std.error <dbl>, #   statistic <dbl>, p.value <dbl>, diet <fct>, mean_trend <dbl>, sort <dbl> 

I have created the following graph: timeline graph

Using this code:

library(tidyverse) library(wesanderson)     ggplot() +         geom_linerange(data = bird_models_traits, aes(ymin = minyear, ymax = maxyear,                                                        colour = diet,                                                       x = fct_reorder(id, desc(sort))),                        size = 1) +         scale_colour_manual(values = wes_palette("Cavalcanti1")) +         labs(x = NULL, y = NULL) +         theme_bw() +         coord_flip() +         guides(colour = F) +         theme(panel.grid.minor = element_blank(),               panel.grid.major.y = element_blank(),               panel.grid.major.x = element_line(),               axis.ticks = element_blank(),               legend.position = "bottom",                panel.border = element_blank(),               legend.title = element_blank(),               axis.title.y = element_blank(),               axis.text.y = element_blank(),               axis.ticks.y = element_blank(),               plot.title = element_text(size = 20, vjust = 1, hjust = 0),               axis.text = element_text(size = 16),                axis.title = element_text(size = 20)) 

Should we go with git flow or trunk based development where development, test and deployment done by separate groups

The focus of our company is not software but we have our own team that develops apps and services to support our business. There are more than 300 from small one-liners to huge fully-fledged web applications to just PL/SQL packages. Our team is generally composed of senior engineers. But we don’t have any open source applications and hardly ever more than 2 developers work on the same project if ever more than just one. So it’s most of the time just one guy working on a project at the same time. The process is defined so that we first do the development, then after we finish our job we pass it to testers and if all the tests pass, they, in turn, pass it to the operations group for deployment. We usually have no strict deadlines because what our business mainly runs on is a bunch of third party software and not what we develop in-house. So I’m a bit confused as to whether we should adopt git flow or trunk based development, or even something else. Does anybody have a similar environment? If so, what way do you go?

Do the Israeli consulates give visa on a separate piece of paper instead of on the passport?

I am a Bangladeshi citizen studying in Columbia University. I wanted to go to Israel for a trip this winter. But Bangladesh still does not recognize Israel as a state and the front page of the passport states that This passport is valid for all the countries in the world except Israel.

I applied for a visa in the Israeli consulate here in NYC. I have just received the confirmation of visa from the Israeli consulate in NYC. I have heard that Israel do not give the visa on the passport. Instead they paste it on a separate piece of paper, and make like a travel permit and they also do not stamp the passport/or any ID during immigration. Is that true? And would I get in trouble entering Bangladesh if I do get a visa on my passport?

I do not have any other passport/nationalities.

Are “extended” variants of a spell considered a separate spell for the purpose of purchase?

Are “extended” versions of spells considered separate items for the purpose of purchasing spells?

For example the spell “Detect enemies” has a variant “Detect enemies, extended”, if I were to purchase “Detect enemies”, do I also get “Detect enemies, extended” for the same cost or must I purchase “Detect enemies, extended” separately?