Joschi
Joschi
CC#
Created by Joschi on 6/24/2024 in #help
✅ EFCore fetching all data in nearly all tables after a single insert
So today I encountered the weirdest error, for which I cannot create a minimal reproducible project. But maybe any of you has any clue on how this is even possible or even why it occours. The project is a .NET7 WebAPI with EFCore pointing towards an SQLServer 2019. We had an object using an auto incrementing int ID.
class MyDbObject
{
public int Id {get;}
//...
}
class MyDbObject
{
public int Id {get;}
//...
}
We changed that to use a StronglyTypedId
[StronglyTypedId]
readonly partial struct ObjectId
{
// This and a lot of plumbing and parsong code is source generated, like a EFCore Value converter and so on.
public int Value {get;}
}
[StronglyTypedId]
readonly partial struct ObjectId
{
// This and a lot of plumbing and parsong code is source generated, like a EFCore Value converter and so on.
public int Value {get;}
}
We used this strong ID implementation multiple times and it works without any problems. Now we had a implicit conversion on the ID for convenience.
[StronglyTypedId]
readonly partial struct ObjectId
{
public static implicit operator ObjectId(MyDbObject obj) => obj.Id;
}
[StronglyTypedId]
readonly partial struct ObjectId
{
public static implicit operator ObjectId(MyDbObject obj) => obj.Id;
}
Now EFCore started to literally fetch the entire database into memory after doing the single and correct INSERT Always selecting all properties of the entire table and sending it back to the client.
_dbContext.Add(myObjectInstance);
await _dbContext.SaveChangesAsync();
_dbContext.Add(myObjectInstance);
await _dbContext.SaveChangesAsync();
Removing the implicit conversion completely resolved this. This did not happen if it was isolated in a unit test and ran against a test database instance. Because of that it most likely is some configuration on the DBContext or the project. I'm at a complete loss, so maybe one of you has any inkling what the cause of this could be.
18 replies
CC#
Created by Joschi on 1/11/2024 in #help
Deploying Blazor WASM with backend API and MySQL Server
Hey there, can someone point me to some good resources on how and where I can deploy a hosted Blazor WASM app and MySQL server for cheap?
7 replies
CC#
Created by Joschi on 10/19/2023 in #help
❔ How to configure an external provider in .Net8 Blazor with individual auth?
Hey guys, I'm having problems adding an external authentication provider to the basic Blazor WebApp template.
services.AddAuthentication(IdentityConstants.ApplicationScheme).AddBattleNet(options =>
{
var bnSection = config.GetSection("Authentication:BattleNet");
var clientId = bnSection["ClientId"];
var clientSecret = bnSection["ClientSecret"];

options.Region = BattleNetAuthenticationRegion.Europe;
options.ClientId = clientId;
options.ClientSecret = clientSecret;
options.Scope.Add("oidc");
}).AddCookie(IdentityConstants.ExternalScheme).AddApplicationCookie();
services.AddAuthentication(IdentityConstants.ApplicationScheme).AddBattleNet(options =>
{
var bnSection = config.GetSection("Authentication:BattleNet");
var clientId = bnSection["ClientId"];
var clientSecret = bnSection["ClientSecret"];

options.Region = BattleNetAuthenticationRegion.Europe;
options.ClientId = clientId;
options.ClientSecret = clientSecret;
options.Scope.Add("oidc");
}).AddCookie(IdentityConstants.ExternalScheme).AddApplicationCookie();
When doing it like this the oidc flow works fine, but now navigating to "Account/Manage" gives an "Error: Unable to load user with ID 'BattleNetId'". This seems to happen, because GetUserAsync(principal) in UserAccessor.cs tries to fetch a user with the BattleNetId from AspNetUsers instead of doing a lookup in AspNetUserLogins first. Is the way I registered that external provider even correct, because I don't entirely understand those AddCookie calls, but without that I get a runtime Error. How do I "correctly" fetch the user if he is logged in using an external provider?
54 replies