C
C#โ€ข8mo ago
Protagonist

Currently Issues with Mapping (Mapperly), in debug mode when call made to API it exits

Repo: https://github.com/Mozin0/ProjectManagement/tree/main/ProjectManagement SubTasks mapping doesnt work and its all very weird.
GitHub
ProjectManagement/ProjectManagement at main ยท Mozin0/ProjectManagem...
Contribute to Mozin0/ProjectManagement development by creating an account on GitHub.
No description
No description
43 Replies
Protagonist
ProtagonistOPโ€ข8mo ago
@๐Ÿฆ viceroypenguin | ๐Ÿฆ‹๐Ÿง๐ŸŒŸ When you can :catpat:
viceroypenguin
viceroypenguinโ€ข8mo ago
well yeah, you're declaring a recursive type. of course it's going to show "string". if it tried to show the type again, then it would be an infinite loop of subtask definitions if you send it the right json, ti'll work fine just ignore the ["string"] there because that's how swagger is avoiding the infinite loop
Protagonist
ProtagonistOPโ€ข8mo ago
ahh okay
Protagonist
ProtagonistOPโ€ข8mo ago
in my database i have a task and a subtask as u can see, also represented by ParentTaskId
No description
Protagonist
ProtagonistOPโ€ข8mo ago
i did these manually Whenever i try to get tasks in debug mode my program exits
Protagonist
ProtagonistOPโ€ข8mo ago
without any subtasks my tasks get works but when a subtask is refering to its parent task thats what happens
No description
viceroypenguin
viceroypenguinโ€ข8mo ago
i'd look at the code that mapperly is generating. probably isn't compatible with a true recursive type
Protagonist
ProtagonistOPโ€ข8mo ago
how do i have access to it?
No description
viceroypenguin
viceroypenguinโ€ข8mo ago
dang, you really pissed of your VS, didn't you
Protagonist
ProtagonistOPโ€ข8mo ago
xDD weird vs code* ๐Ÿ˜›
viceroypenguin
viceroypenguinโ€ข8mo ago
oh, /shrug i don't touch VSC the mapperly file opens just fine for me in VS ewww..... ITaskManager? and using block scoped namespaces? are we in 2010? please stop public IQueryable<ProjectTaskDto> GetTasks() - no. just no. do not do this so the root problem is that you're using non-Expressions to try and convert db queries to C# models don't do that also, querying recursive data types from the database requires some unique magic. i don't even know if EFC can do that magic. (since i don't use EFC) you should look up EFC recursive CTE i know that you can do it when you bolt on linq2db.entityframeworkcore library, and use the l2db query engine to do it. [HttpPut("{parentId}subtasks/{id}")] invalid url
Protagonist
ProtagonistOPโ€ข8mo ago
wats wrong with the interface xD
viceroypenguin
viceroypenguinโ€ข8mo ago
$whynotca
MODiX
MODiXโ€ข8mo ago
CA is not necessarily difficult to understand conceptually, but they're difficult to build and difficult to maintain. When you build a real project, you will quickly (as often evidenced on this server) run into questions like "Is this an infrastructure object or a domain object?" or "Should I implement this contract in the infrastructure or the application?". Questions that a) take your time to ponder and ultimately answer, and b) distract you from doing your actual work. It also adds unnecessary abstractions, by forcing you to use layers: both unnecessary layers and unnecessary decoupling between layers. For example, CA would generally argue that you should abstract the database into repositories and services should depend on an interface for the repository. However, modern ORMs like EFC already implement the repository pattern, by abstracting the implementation of a query via LINQ. Furthermore, in most applications, there's only one implementation of IXxxRepository - so why create the interface abstraction? Instead, it's generally better to get rid of nearly all interfaces, keeping only ones that truly have more than one implementation; simplifying maintenance because any change to an api only needs to be done in one class instead of both class and interface. Smush all of the code down into a single Web project, or possibly two: Web and Services projects; removing any questions about "which project does this class go into?". Organize your code well in the Web project, with all of the User-related services/controllers/models/etc under /Features/Users/Xxx; all of the Order-related services/controllers/models/etc under /Features/Orders/Xxx; etc. Then it will be easy to find and maintain all of the code related to such and such feature. Any Infrastructure code (like emails, behaviors, startup code, etc.) can go under /Infrastructure/Xxx, and any non-infrastructure code that's not related to a feature can go under /Features/Shared.
Protagonist
ProtagonistOPโ€ข8mo ago
I guess i still have things picked up from school xD I thought this was recommended with Dto's instead of Ienymerables
viceroypenguin
viceroypenguinโ€ข8mo ago
no, abso-fucking-lutely not passing around IQueryable<>s is asking for trouble, and you should not ever do it. only time you can use IQueryable<> is if you're creating a query inside of a class. it should always be materialized before leaving the class aka any public method should only use IEnumerable, List, etc.
Protagonist
ProtagonistOPโ€ข8mo ago
Oops thats right just a single statement should do got it ill change to expressions
MODiX
MODiXโ€ข8mo ago
viceroypenguin
also, querying recursive data types from the database requires some unique magic. i don't even know if EFC can do that magic. (since i don't use EFC)
React with โŒ to remove this embed.
Protagonist
ProtagonistOPโ€ข8mo ago
from what ive researched quickly just now, looks like EFC doesnt support CTE
viceroypenguin
viceroypenguinโ€ข8mo ago
then use l2db.efc and don't use mapperly for that https://linq2db.github.io/articles/sql/CTE.html
Protagonist
ProtagonistOPโ€ข8mo ago
is ADO.net needed for this? it says so in the get started but if i remmeber correctly ADO.net is for raw sql and isnt it a bit outdated? oops yes it is forgot the /
viceroypenguin
viceroypenguinโ€ข8mo ago
slight distinction here: * ado.net is the foundation for everything db related undera ll systems, so definitely not a "not needed" * but definitely don't use ado.net directly anymore, because it's outdated but that's eht point of the article i sent you. use linq2db.efc and you can write recursive queries in linq instead of raw sql
Protagonist
ProtagonistOPโ€ข8mo ago
hmm that makes sense, would i scrap my use of mapperly since project and tasks & subtasks have a connection, or is it possible to keep it for project and tasks also you never said why this was ew
viceroypenguin
viceroypenguinโ€ข8mo ago
i did. you interpreted correctly, that it was because it's an interface. you might be able to keep fro projects, but probably not
Protagonist
ProtagonistOPโ€ข8mo ago
that sucks so would it have to be manual mapping then i thought interfaces was a good thing? to offer abstraction where possible
MODiX
MODiXโ€ข8mo ago
MODiX#0152
CA is not necessarily difficult to understand conceptually, but they're difficult to build and difficult to maintain. When you build a real project, you will quickly (as often evidenced on this server) run into questions like "Is this an infrastructure object or a domain object?" or "Should I implement this contract in the infrastructure or the application?". Questions that a) take your time to ponder and ultimately answer, and b) distract you from doing your actual work. It also adds unnecessary abstractions, by forcing you to use layers: both unnecessary layers and unnecessary decoupling between layers. For example, CA would generally argue that you should abstract the database into repositories and services should depend on an interface for the repository. However, modern ORMs like EFC already implement the repository pattern, by abstracting the implementation of a query via LINQ. Furthermore, in most applications, there's only one implementation of IXxxRepository - so why create the interface abstraction? Instead, it's generally better to get rid of nearly all interfaces, keeping only ones that truly have more than one implementation; simplifying maintenance because any change to an api only needs to be done in one class instead of both class and interface. Smush all of the code down into a single Web project, or possibly two: Web and Services projects; removing any questions about "which project does this class go into?". Organize your code well in the Web project, with all of the User-related services/controllers/models/etc under /Features/Users/Xxx; all of the Order-related services/controllers/models/etc under /Features/Orders/Xxx; etc. Then it will be easy to find and maintain all of the code related to such and such feature. Any Infrastructure code (like emails, behaviors, startup code, etc.) can go under /Infrastructure/Xxx, and any non-infrastructure code that's not related to a feature can go under /Features/Shared.
React with โŒ to remove this embed.
viceroypenguin
viceroypenguinโ€ข8mo ago
It also adds unnecessary abstractions, by forcing you to use layers: both unnecessary layers and unnecessary decoupling between layers. For example, CA would generally argue that you should abstract the database into repositories and services should depend on an interface for the repository. However, modern ORMs like EFC already implement the repository pattern, by abstracting the implementation of a query via LINQ. Furthermore, in most applications, there's only one implementation of IXxxRepository - so why create the interface abstraction? Instead, it's generally better to get rid of nearly all interfaces, keeping only ones that truly have more than one implementation; simplifying maintenance because any change to an api only needs to be done in one class instead of both class and interface.
namely, it's unnecessary and increases the work that you have to do to maintain your code
Protagonist
ProtagonistOPโ€ข8mo ago
That makes sense actually Tbh i found it useless but just thought thats wat was best and CA
viceroypenguin
viceroypenguinโ€ข8mo ago
yeah, don't do CA
Protagonist
ProtagonistOPโ€ข8mo ago
so do i abandon mostly everything that was taught in schoold cos it was outdated xD, we even was taught how to use ado.net n that was 2-3 years ago I will refactor n add things in my code and @ you when I've done them
Protagonist
ProtagonistOPโ€ข8mo ago
this is just for the Get method but i managed to do it using the package u suggested, thank you
No description
Protagonist
ProtagonistOPโ€ข8mo ago
I will still keep this open incase i struggle with other methods etc tmrw
leowest
leowestโ€ข8mo ago
EF can do it fine as well
var projects = await db.Projects
.Include(x => x.Tasks)
.ThenInclude(y => y.SubTasks)
.Select(p => p.ToDto())
.ToListAsync();
var projects = await db.Projects
.Include(x => x.Tasks)
.ThenInclude(y => y.SubTasks)
.Select(p => p.ToDto())
.ToListAsync();
ThenInclude is filling the subtasks here.
viceroypenguin
viceroypenguinโ€ข8mo ago
what about y.SubTasks.SubTasks?
leowest
leowestโ€ข8mo ago
then u would need another ThenInclude is my understanding as depth goes if u mean a way to naturally transverse it
viceroypenguin
viceroypenguinโ€ข8mo ago
yeah, that's the problem
leowest
leowestโ€ข8mo ago
without having to specify depth
viceroypenguin
viceroypenguinโ€ข8mo ago
with a recursive dataset, to properly go all the way down, you need a recursive cte i love them, but EFC doesn't support them natively
leowest
leowestโ€ข8mo ago
yeah indeed @viceroypenguin | ๐Ÿฆ‹๐Ÿง๐ŸŒŸ I assume u can probably cook something up that can go any depth thou... like a extension method u specify the depth but yeah it would be nice if it would have recursive CTE
Protagonist
ProtagonistOPโ€ข8mo ago
either way this is a good learning curve for me, learning a new library and how it can work alongside EF Firstly id limit it to a task has subtasks, then I'll see if there is a use for subtasks to have subtasks
leowest
leowestโ€ข8mo ago
yep is it a good learning regardless because you will get to understand about recursion and its pitfalls in db
Protagonist
ProtagonistOPโ€ข8mo ago
exactly ๐Ÿ˜›
Want results from more Discord servers?
Add your server