Joschi
Reset identity colums EF Core error.
You could consider alternatives to what you are doing now. Both are more or less a variant on "don't manually try to reset your database state".
The first would be to call context.EnsureDeleted() followed by context.EnsureCreated() at the start of your tests. This would delete the database and then create one from your code first context. (Note this does not use migrations, it just creates it from the existing config directly).
The second option would be to use test containers, which creates a fresh DB as a docker container for your tests.
MS has a whole series on articles with guidance on how to test applications using efcore https://learn.microsoft.com/en-us/ef/core/testing/
17 replies
Data fetching in components?
If you use prerendering, then OnParameterSet will always be called twice.
https://github.com/dotnet/aspnetcore/issues/30037
It will also always be rerun, when blazor believes the parameter may have changed.
If your db call does not depend on the parameter I suggest moving it into OnInitializedAsync after the call to the base method.
If it has to be in OnParameterSet you could create a CancellationToken using a CancellationTokenSource and cancel the previous db call.
Or just create a new DbContext.
13 replies
Data fetching in components?
partial
allows you to split a class between different files. Like you could now go into a diferent .cs file, redeclare the class and add some properties or methods.
Most of the time it is only done to allow source generators to extend your class.
protected
as an accessibility modifier means "Only I and inheriting classes can access this variable". So that already accomplishes your goal.13 replies
Data fetching in components?
This is what I'm using
And then you can just inherit it in your component with the
@inherits
directive.
But you are responsible to ensure that the user cannot trigger two actions at the same time.
For example if you have two buttons, both resulting in a database call, it would throw a concurrency exception, if the user clicks both buttons in rapid succession, before the first database call finishes.13 replies
How to convert a whole json file to C# classes with Newtonsoft.Json?
Yes, because that is not how you deal with Json.
You want to use deserialization.
https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/deserialization
43 replies