Because these are logs, using EF Core directly for the relationship felt weird, because it would create foreign keys and we don't really want those.
So this solution implements a manual join. In fact, a LEFT JOIN, because we still want to show logs that have no fitting UserId set.
The Microsoft docs show how EF Core converts a "GroupJoin(), SelectMany(), DefaultIfEmpty()" combination into a LEFT JOIN.
And this works as expected (notice the LEFT JOIN):
[18:49:09 INF] Executed DbCommand (5ms) [Parameters=[@__Table_0='Games', @__rowStr_1='1', @__p_3='25', @__p_2='0'], CommandType='Text', CommandTimeout='30']
SELECT a.row_id AS "RowId", CASE
WHEN (u.id IS NULL) THEN 'Unknown_User'
ELSE u.user_name
END AS "UserName", a.created AS "Created", a.table_name AS "TableName", a.changed AS "Changed", a.kind AS "Kind"
FROM auto_history AS a
LEFT JOIN users AS u ON a.user_id = u.id
WHERE (a.table_name = @__Table_0) AND (a.row_id = @__rowStr_1)
ORDER BY a.created DESC
LIMIT @__p_3 OFFSET @__p_2
Resolves #1584 .
Because these are logs, using EF Core directly for the relationship felt weird, because it would create foreign keys and we don't really want those. So this solution implements a manual join. In fact, a LEFT JOIN, because we still want to show logs that have no fitting UserId set.
The Microsoft docs show how EF Core converts a "GroupJoin(), SelectMany(), DefaultIfEmpty()" combination into a LEFT JOIN. And this works as expected (notice the LEFT JOIN):