November
Beginner looking for project ideas to practice C# – any suggestions?
Batching is just the concept of combining all your updates into a single query:
https://learn.microsoft.com/en-us/ef/core/performance/efficient-updating?tabs=ef7
39 replies
Beginner looking for project ideas to practice C# – any suggestions?
It is a basic CRUD app that solves a specific problem (handling csv). And you can incrementally introduce more complexity to test yourself:
E.g., handling duplicate data, handling different file types
39 replies
Beginner looking for project ideas to practice C# – any suggestions?
There's a few ways to solve it. You can set up an index on "Title" and set a constraint to make it unique and fail on inserting duplicates.
Or you can query to find existing records and do an update or insert query, updating existing records and inserting new ones.
I would say this is more or less this is junior level code.
39 replies
Beginner looking for project ideas to practice C# – any suggestions?
@Notchu Thoughts:
This is a pretty good start. I think it captures the requirements of the assignment.
Some things I noticed:
- In your ctor for FilmData, you can do
FilmData(Guid? id = null)
and update the body to null coalesce to a new Guid. That way you can use this ctor in the Update controller method and don't need to manually map your dto.
- I don't like the mixing of sometimes returning a service result object and sometimes not for the DataService methods. I'd prefer if they were all unified to either always return a ServiceResult wrapper or not
Some other design considerations:
- consider what happens if someone uploads a csv document that includes a Film data that describes a record already in the database. How should the api handle this?
Sorry if the formatting is bad, I'm on mobile.39 replies
What to learn next?
Asynchronous programming is a core feature of programming in general.
Let's say we want to call some web-based service to fetch some data, for example, weather data via some public weather api.
We might do something like:
var weatherData = GetWeatherData()
But the problem here is that GetWeatherData()
takes some unknown time to execute. It doesn't instantly provide us with information of the weather. So we want our code to pause here and allow our program to go do other stuff and only once we get a result back to resume execution.
So instead of returning some weather data, our code returns a Task
of weather data. Task
in C# represents some work to be done. And we can call and await this work to be done using certain keywords.
async
this keyword is used to mark functions and tell the compiler that this function can perform work asynchronously. This should pretty much always be used with a return type of Task
or Task<T>
. E.g., public async Task<GetWeatherDto> GetWeatherData()
await
is the keyword that "waits" for the Task to finish before moving on. E.g., var weatherData = await GetWeatherData()
this wait for a response before storing the result in weatherData.150 replies
AutoMapper example projects with mapping profiles
that's exactly what AM was made for. Convention based mapping with minimal/no additional transformations to the dest props.
I'm not sure how you can avoid writing the profiles if that's what you are referring to.
64 replies
AutoMapper example projects with mapping profiles
I mean, using Automapper or any other mapper, is a design choice and you have to be aware of the tradeoffs. AutoMapper is only bad when it's misused. The biggest valid criticism is that it moves some errors that would conventionally be compile-time errors to runtime errors, which can make debugging a headache (mentioned above).
That being said, on most projects I think AM is probably not needed. I would actually recommend just writing the maps yourself.
64 replies
AutoMapper example projects with mapping profiles
there is nothing wrong with automapper as long as you are aware of the tradeoffs between it and other solutions.
the most straight forward way is to set up a mapper profile for each of your entities. I usually declare them in the same file.
https://docs.automapper.org/en/stable/Configuration.html
I usually scan the assembly to auto register the profiles to the mapper config.
64 replies
What to learn next?
This depends. I didn't read the project requirements.
But if the logic for a CheckingAccount and a SavingAccount are exactly the same, then there's no need to use an abstract method.
Abstract methods are useful when you want all your subclasses to do a certain function, but the details and behavior differs depending on the subclass.
150 replies
What to learn next?
You have this base class called
Account
that is meant to be the blueprint for all of your subclasses.
And you have a few subclasses, but it looks like the logic is all pretty much the same, no? So what is the purpose?
Why not:
Account businessAccount = new Account()
Account checkingAccount = new Account()
?
If you anticipate the logic to differ, then you can have this abstract/subclass relationship. But you would need Deposit
to be abstract and be on the abstract class.
Refer to these concepts:
Abstract classes
Interfaces
Polymorphism150 replies