Naarfy
Naarfy
CC#
Created by Naarfy on 3/11/2024 in #help
Blazor page reloading after db update ?
I have a comments table. I querry my Users table to get the DateTIme where the user last saw the comments and I group the comments based on that to get oldComments, newComments. Then I update my user. The issue I'm having it my new comment shows up for half a second in "New comments" before moving to "Old Comments"
protected override async Task OnInitializedAsync()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
comments = await dbContext.Comments.ToListAsync();
totalComments = comments.Count;
var user = authState.User;

if (user.Identity.IsAuthenticated)
{
loggedInUserGuid = user.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value;
}

appUser = await dbContext.Users.FindAsync(loggedInUserGuid);
lastSeenComments = appUser.LastSeenComments;
var groupedComments = comments.GroupBy(c => c.CreatedAt <= lastSeenComments)
.ToDictionary(g => g.Key, g => g.ToList());

oldComments = groupedComments.GetValueOrDefault(true, new List<Comment>());
newComments = groupedComments.GetValueOrDefault(false, new List<Comment>());

appUser.LastSeenComments = DateTime.UtcNow;
dbContext.Users.Update(appUser);
await dbContext.SaveChangesAsync();

}
protected override async Task OnInitializedAsync()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
comments = await dbContext.Comments.ToListAsync();
totalComments = comments.Count;
var user = authState.User;

if (user.Identity.IsAuthenticated)
{
loggedInUserGuid = user.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value;
}

appUser = await dbContext.Users.FindAsync(loggedInUserGuid);
lastSeenComments = appUser.LastSeenComments;
var groupedComments = comments.GroupBy(c => c.CreatedAt <= lastSeenComments)
.ToDictionary(g => g.Key, g => g.ToList());

oldComments = groupedComments.GetValueOrDefault(true, new List<Comment>());
newComments = groupedComments.GetValueOrDefault(false, new List<Comment>());

appUser.LastSeenComments = DateTime.UtcNow;
dbContext.Users.Update(appUser);
await dbContext.SaveChangesAsync();

}
3 replies
CC#
Created by Naarfy on 3/4/2024 in #help
Blazor - No event handlers associated
Hi. I have a simple Blazor project (.NET8) I have fields who write to a database on click. The issue I have is most of the time - but not everytime - I click on an input field, I get the error message here https://pastebin.com/Y0FxsfUe When that happens, I can't invoke my submit function (I get the same error with the handler ID incremented by 1) sometimes I restart the server and it works I can upsert my post no problem. here is my code https://pastebin.com/gcWnRyRB
5 replies
CC#
Created by Naarfy on 3/1/2024 in #help
Converting the Sqlite template to Postgresql
Hello, I started a new project with the template
dotnet new blazor --auth Individual --interactivity Auto
dotnet new blazor --auth Individual --interactivity Auto
It comes with a Sqlite Db. I want to change it to Postgres. I installed the packages and change UseSqlite to UseNpgsql. It connects to my db and the initial migration works, it creates the tables on my db. The issue i'm having is if I try to create a user for example, I get :
PostgresException: 42804: column "EmailConfirmed" is of type integer but expression is of type boolean POSITION: 303
PostgresException: 42804: column "EmailConfirmed" is of type integer but expression is of type boolean POSITION: 303
I guess there is some casting going on and Postgres doesn't want to use a boolean as an integer. If I look into
ApplicationDbContextModelSnapshot.cs
ApplicationDbContextModelSnapshot.cs
I see :
b.Property<bool>("EmailConfirmed").HasColumnType("INTEGER");
b.Property<bool>("EmailConfirmed").HasColumnType("INTEGER");
The issue I have is that this file is auto generated. If I search the field EmailConfirmed that's pretty much all I have. The variable declaration and this. At that point can I tell EF to make sure the colu;mn stays a bool ?
8 replies
CC#
Created by Naarfy on 10/29/2023 in #help
❔ Blazor @bind not triggering update
Hello everyone I'm trying to display a select that will trigger a database fetch on select and display the values with Blazor and .NET8. The issue i'm facing is that @bind doesnt seem to update my variable. I also try different things with @onchange, @oninput or @onselect but it seems like it's never firing any function Obviously I'm missing something here but I can't see what
9 replies
CC#
Created by Naarfy on 9/12/2023 in #help
✅ finding dotnet 8.0.0-rc.1.23419.4 ?
Hi. I'm trying to get dotnet-ef working with dotnet preview 8.0 It seems that it supports rc 1.23419.4 here https://www.nuget.org/packages/dotnet-ef/8.0.0-rc.1.23419.6#supportedframeworks-body-tab But I can't find it anywhere. Here is my log
dotnet ef
You must install or update .NET to run this application. ─╯

App: /Users/user/.dotnet/tools/dotnet-ef
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '8.0.0-rc.1.23419.4' (x64)
.NET location: /usr/local/share/dotnet

The following frameworks were found:
6.0.21 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
7.0.10 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
8.0.0-preview.1.23110.8 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
8.0.0-preview.5.23280.8 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
8.0.0-preview.7.23375.6 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Learn more:
https://aka.ms/dotnet/app-launch-failed
dotnet ef
You must install or update .NET to run this application. ─╯

App: /Users/user/.dotnet/tools/dotnet-ef
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '8.0.0-rc.1.23419.4' (x64)
.NET location: /usr/local/share/dotnet

The following frameworks were found:
6.0.21 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
7.0.10 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
8.0.0-preview.1.23110.8 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
8.0.0-preview.5.23280.8 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
8.0.0-preview.7.23375.6 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Learn more:
https://aka.ms/dotnet/app-launch-failed
7 replies
CC#
Created by Naarfy on 3/22/2023 in #help
❔ cannot resolve AddDatabaseDeveloperPageExceptionFilter();
Hello, I'm trying to follow https://learn.microsoft.com/en-us/aspnet/core/tutorials/min-web-api?view=aspnetcore-7.0&tabs=visual-studio-mac I had an issue with the class Todo who couldn't be resolved but that was an easy fix (using TodoApi) however I have a problem with
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
Rider gives me the error
Cannot resolve symbol 'AddDatabaseDeveloperPageExceptionFilter'
Cannot resolve symbol 'AddDatabaseDeveloperPageExceptionFilter'
What am I doing wrong ? Thanks
3 replies