Need some help with my end-point
So i have this end point:
My model:
The query works fine in mssql, some of the data is indeed NULL, my guess would be that calling the below function on that data gives the error?
This is the error im getting:
This is my first Dotnet project so all tips and hints are welcome!
20 Replies
don't know much about this, but as a guess, if some things are nullable, you have to mark them as nullable in the models
I wonder, why
FromSqlRaw
and not just using EF?
Is the issue, perhaps, that you're selecting only some properties with your query?
Because that would leave the non-selected properties null
, yesThis actually worked like this:
No reason, just first project and watching tutorials
Just use EF then
And
.Select()
into a DTO
That way you won't have to mark properties as nullable when they shouldn't be nullable on the databaseCould u show me an example of how u would use that ?
This would give you a list of objects with just
Type
and Sequence
pulled from your Step
entity
Without having to mark other properties as nullableWhere do u implement the query in this example ?
Nowhere
You don't write a single line of SQL code
EF generates it for you
My code would generate something like
i see, and how does it know to what table it should talk ?
DbContext
represents the database
DbSet
s within it represent the tables
Tables generated by EF will be named after their respective DbSetsI see, and i have 1 query that just pulls all the database names that have a certain table. this this also possible with EF ?
First of all, why would you have multiple databases?
Second of all, I'm afraid not
each client has its own database where all of its workflows are saved, not something i came up with but something i have to work with unfortunately
its an application where u can visualize these workflows
Ah, oof, some demented version of multi-tenancy
with C# as backend
In that case, yeah, you'd have to rely on SQL
But if you do want to execute arbitrary SQL, don't use EF for that, use Dapper
Do you maybe have a good tutorial for a good set up.
I first used tim correys minimal API tutorial but people told me i shouldnt do that because its not for a beginner project.
Also problem was that i didnt really understand the code, you helped me before and I had a problem with dynamic, dynamic. idk if you remember.
I tried fixing it and realised i dont really understand my own code so I decided to just start fresh and keep things a basic as possible.
https://github.com/DapperLib/Dapper
https://www.learndapper.com/
Far as the API itself, going with the regular controllers template was definitely a good choice
I'm afraid I don't have any recommended tutorials on that, though
I tend to learn by doing
Right i think API itself set up is fine and i understand it. ill just dive into dapper. thanks!