Joschi
Joschi
CC#
Created by Zoli on 1/3/2025 in #help
Resolving Entity Framework Core Tracking Issues with Shared Relationships in .NET MAUI and SQLite
Not really. Most of the time your dbcontext should not outlive a SaveChanges call. One dbContext should more or less be used for one unit of work.
6 replies
CC#
Created by Cydo on 12/29/2024 in #help
Trying to understand proper error handling
Not too familiar with generation, because we work with blazor and just share our dtos. I only used Kiota (a few years ago) and that doesn't really care about your defined errors. It will just throw exceptions on non success in any case.
160 replies
CC#
Created by Cydo on 12/29/2024 in #help
Trying to understand proper error handling
To me it sounds like you should give minimal apis with the REPR pattern a try. Like FastEndpoints. It also has strongly typed endpoint methods with union responses, which will end up in the OpenApi schema.
160 replies
CC#
Created by Cydo on 12/29/2024 in #help
Trying to understand proper error handling
Would you elaborate how? Because that would be something really interesting to build.
160 replies
CC#
Created by Cydo on 12/29/2024 in #help
Trying to understand proper error handling
Some people only have one endpoint in each controller class when using mvc. It is often done to reduce the dependencies in each controller. Regarding your problems above with exceptions and results. The advantage of an Result implementation is, that you are forced to handle errors. And you are aware that errors could happen in a method. Unless it is documented or you read the methods source, you cannot know if and which exceptions it may throw. In APIs this will result in 500 responses, which is often undesired. What we currently do is to map our different Error types to the corresponding api error. So a NotFoundError would return a 404. Having it well documented in an OpenApi schema, without manually defining the possible errors that could happen at this specific endpoint is really hard. Probably even impossible in MVC. Mainly because everything is boiled down to IActionResult. And its hard to know at compile time which actual types could maybe occour. But honestly not that important unless you develop an API meant for public consumption.
160 replies
CC#
Created by Bananas on 11/24/2024 in #help
Manage small university project
No! You won't be able to distinguish between it giving good advice and it hallucinating.
23 replies
CC#
Created by Bananas on 11/24/2024 in #help
Manage small university project
Don't worry about something like that as a beginner. Just try to write down what you want your app to do and get started. Don't worry about the "correct" way of doing it, just try to get something working.
23 replies
CC#
Created by FestivalDelGelato on 11/23/2024 in #help
✅ doubts about migrations
Yeah right thinking about it, they have to be or EFCore could not migrate the DB at runtime.
10 replies
CC#
Created by FestivalDelGelato on 11/23/2024 in #help
✅ doubts about migrations
Are the designer and migration files even icluded in the compilation?
10 replies
CC#
Created by FestivalDelGelato on 11/23/2024 in #help
✅ doubts about migrations
What problem would you solve by moving them into another problem or squashing them?
10 replies
CC#
Created by steven preadly on 11/22/2024 in #help
do defined route added to the the routes table when the app.Run() executed or before?
Thats not the actual Pipeline. Thats just the registering of the pipeline. The pipeline runs, when a http request comes in. And the program only runs after app.Run is called.
5 replies
CC#
Created by steven preadly on 11/22/2024 in #help
do defined route added to the the routes table when the app.Run() executed or before?
Do you mean stepping through in the Program.cs?
5 replies
CC#
Created by on 11/21/2024 in #help
When should one use a custom delegate instead of Func/Action/Predicate?
Multicast delegates is how events are implement in C# as far as I know. Delegates are not that often used, but they are valuable if you go deeper into the functional style of C#. https://www.youtube.com/watch?v=2TXvwUgaMHs&t=1s
122 replies
CC#
Created by Headless on 11/22/2024 in #help
Manipulating Strings
The idea would be, that you have a full script, 300+ pages long. Now you want to convert all the camera directions and positions into the case you prefer. It's way faster writing code for you to do that. What you got there is just the bases for doing it.
13 replies
CC#
Created by Headless on 11/22/2024 in #help
Manipulating Strings
Strings in C# are immutable. Meaning you cannot change the actual string itself, just creating new ones. So what you want to do is extract the parts you want to change, change them and then rebuild the full string. You are more or less doing it, but I guess your input should be the original unmodified string. Without any ToUpper mixed in there like you did. There are ways of doing this more efficient, but you should not worry about that right now.
13 replies
CC#
Created by Headless on 11/22/2024 in #help
Manipulating Strings
The code on the right is your code correct?
13 replies
CC#
Created by Headless on 11/22/2024 in #help
Manipulating Strings
Ok what exactly is your goal here? Can you post the exact final output you expect?
13 replies
CC#
Created by Headless on 11/22/2024 in #help
Manipulating Strings
What exactly is your problem here? Why cant you just call ToUpper on that string?
13 replies
CC#
Created by on 11/21/2024 in #help
Null check
There is one small reason for is over == and that is, that == could technically be overwritten. While is cannot.
12 replies
CC#
Created by Ahata on 11/18/2024 in #help
Inheritance
Ok found the problem and it has nothing to do with inheritance.
c#
private Texture2D ltexture;

public Texture2D texture
{
get{ return ltexture;}
set{ ltexture = texture;}
}

public Entity(Texture2D texture, Vector2 position)
{
this.position = position;
this.texture = texture;
}
c#
private Texture2D ltexture;

public Texture2D texture
{
get{ return ltexture;}
set{ ltexture = texture;}
}

public Entity(Texture2D texture, Vector2 position)
{
this.position = position;
this.texture = texture;
}
Your constructor sets the value of the texture property, but your setter sets its value to itself. The setter has to set the value of the backing field (ltexture) to value.
c#
private Texture2D ltexture;

public Texture2D texture
{
get{ return ltexture;}
set{ ltexture = value;}
}

public Entity(Texture2D texture, Vector2 position)
{
this.position = position;
this.texture = texture;
}
c#
private Texture2D ltexture;

public Texture2D texture
{
get{ return ltexture;}
set{ ltexture = value;}
}

public Entity(Texture2D texture, Vector2 position)
{
this.position = position;
this.texture = texture;
}
While we are at it. You should adhere to the C# format standards. Properties start with uppercase letters and fields start lowercase and often even with a underscore. And if you don't have a special reason for creating a backing field yourself you should use auto properties.
c#
class Entity
{
// Auto Property
public Vector2 Position {get; set;}

// Backing Field
private Texture2D _texture;

// Property with Backing Field
public Texture2D Texture
{
get{ return _texture;}
set{ _texture = value;}
}

public Entity(Texture2D texture, Vector2 position)
{
Position = position;
Texture = texture;
}
}
c#
class Entity
{
// Auto Property
public Vector2 Position {get; set;}

// Backing Field
private Texture2D _texture;

// Property with Backing Field
public Texture2D Texture
{
get{ return _texture;}
set{ _texture = value;}
}

public Entity(Texture2D texture, Vector2 position)
{
Position = position;
Texture = texture;
}
}
19 replies