Zoli
Zoli
CC#
Created by Zoli on 3/13/2025 in #help
How to Properly Synchronize ViewModel and Model in MVVM (CommunityToolkit.Mvvm)
In a reactive approach for an edit operation, FooModel is passed to FooViewModel via the constructor. However, this means that any modifications made in the ViewModel will be directly reflected in the original model, even if the user cancels the operation without saving. How can I ensure that changes are only applied to the original model after a successful save operation while still leveraging reactivity? What is the best practice for maintaining the original state if the user decides to discard the changes?
7 replies
CC#
Created by Zoli on 1/19/2025 in #help
✅ UNIQUE constraint failed
Ohhh looks good thanks a lot 🍻 Probably it will solve my issue. One more question if you dont mind. I have the ExerciseVariant table which is kind of metadata so only read only.
[Table(nameof(ExerciseVariant))]
public class ExerciseVariant
{
[Key]
public Guid Id { get; set; }

public ICollection<Exercise> Exercises { get; } = new List<Exercise>();

// Other properties
}
[Table(nameof(ExerciseVariant))]
public class ExerciseVariant
{
[Key]
public Guid Id { get; set; }

public ICollection<Exercise> Exercises { get; } = new List<Exercise>();

// Other properties
}
Do I need this list of exercise at all? Each exercise can have one exercise variant, and exercise variant can be used for multiple exercise
21 replies
CC#
Created by Zoli on 1/19/2025 in #help
✅ UNIQUE constraint failed
So in this case i register only UnitOfWork in the Di so means all repository gets the same DbContext. How is it possible to inject new for each repository?
21 replies
CC#
Created by Zoli on 1/19/2025 in #help
✅ UNIQUE constraint failed
Is using the same DbContext should be avoided?
21 replies
CC#
Created by Zoli on 1/19/2025 in #help
✅ UNIQUE constraint failed
Yes I know just wanted to extend with some custom methods and etc.
21 replies
CC#
Created by Zoli on 1/19/2025 in #help
✅ UNIQUE constraint failed
No description
21 replies
CC#
Created by Zoli on 1/19/2025 in #help
✅ UNIQUE constraint failed
No description
21 replies
CC#
Created by Zoli on 1/19/2025 in #help
✅ UNIQUE constraint failed
Still the same.
21 replies
CC#
Created by Zoli on 1/19/2025 in #help
✅ UNIQUE constraint failed
When I want to create a workout:
var first = await _dbContext.ExerciseVariant.FirstOrDefaultAsync();
var workout = new Workout()
{
Title = "test",
};
var exercise = new Exercise()
{
ExerciseVariant = first,
ExerciseVariantId = first.Id
};

workout.Exercises.Add(exercise);

await _dbContext.Workout.AddAsync(workout).ConfigureAwait(false);
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
var first = await _dbContext.ExerciseVariant.FirstOrDefaultAsync();
var workout = new Workout()
{
Title = "test",
};
var exercise = new Exercise()
{
ExerciseVariant = first,
ExerciseVariantId = first.Id
};

workout.Exercises.Add(exercise);

await _dbContext.Workout.AddAsync(workout).ConfigureAwait(false);
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
I am getting an exception as
An error occurred while saving the entity changes.See the inner exception for details. // ---> Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 19: 'UNIQUE constraint failed: ExerciseVariant.Id'.
What am I doing worng? Since ExerciseVariant is read only kind of metadata do I need to add ? public ICollection<Exercise> Exercises { get; } = new List<Exercise>();
21 replies
CC#
Created by Zoli on 1/17/2025 in #help
User ID on Client Side or Not?
Technicly I cannot have any issue by exposing the userId to the client till I have authentication on every endpoint?
5 replies
CC#
Created by Zoli on 1/17/2025 in #help
User ID on Client Side or Not?
I forgot to mention all user ids are guid, and i use authentication on the server side so it is not countable. I guess.
5 replies
CC#
Created by Zoli on 1/10/2025 in #help
MongoDB.Driver.Linq.ExpressionNotSupportedException: ' Expression not supported: i.ToClaim()
Ohh thanks, I wouldn't find this for sure 😄 agree it must be that the reason.
6 replies
CC#
Created by Zoli on 1/10/2025 in #help
MongoDB.Driver.Linq.ExpressionNotSupportedException: ' Expression not supported: i.ToClaim()
No description
6 replies
CC#
Created by Zoli on 1/10/2025 in #help
Determining Feed Ownership for Edit/Delete Functionality in a client application
Thank you for the input!. Ovbiously on the server side i still need to validate the incoming edit/delete request for particular feedItem (does the authenticated user own the target feed item).
4 replies
CC#
Created by Zoli on 1/3/2025 in #help
Resolving Entity Framework Core Tracking Issues with Shared Relationships in .NET MAUI and SQLite
Shall I call _dbContext.ChangeTracker.Clear() after each await dbContext.SaveChangesAsync();?
6 replies
CC#
Created by Zoli on 1/3/2025 in #help
Resolving Entity Framework Core Tracking Issues with Shared Relationships in .NET MAUI and SQLite
Data Context Configuration:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Configure Exercise -> ExerciseVariant relationship
modelBuilder.Entity<Exercise>()
.HasOne(e => e.ExerciseVariant)
.WithMany(ev => ev.Exercises)
.HasForeignKey(e => e.ExerciseVariantId);

// Configure Workout -> Exercise relationship
modelBuilder.Entity<Workout>()
.HasMany(w => w.Exercises)
.WithOne(e => e.Workout)
.HasForeignKey(e => e.WorkoutId)
.OnDelete(DeleteBehavior.Cascade);

base.OnModelCreating(modelBuilder);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Configure Exercise -> ExerciseVariant relationship
modelBuilder.Entity<Exercise>()
.HasOne(e => e.ExerciseVariant)
.WithMany(ev => ev.Exercises)
.HasForeignKey(e => e.ExerciseVariantId);

// Configure Workout -> Exercise relationship
modelBuilder.Entity<Workout>()
.HasMany(w => w.Exercises)
.WithOne(e => e.Workout)
.HasForeignKey(e => e.WorkoutId)
.OnDelete(DeleteBehavior.Cascade);

base.OnModelCreating(modelBuilder);
}
The Issue: When I attempt to create a workout and associate it with an existing ExerciseVariant, I encounter the following error: The instance of entity type 'ExerciseVariant' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked. I have already tried using AsNoTracking when retrieving the ExerciseVariant, but the issue persists. How can i solve this issue? Is there a recommended way to handle such scenarios where an entity with shared relationships needs to be reused?
6 replies
CC#
Created by Zoli on 1/3/2025 in #help
Resolving Entity Framework Core Tracking Issues with Shared Relationships in .NET MAUI and SQLite
Entity Structure: Here is the class structure for my entities and their relationships:
public class Workout
{
[Key]
public Guid Id { get; set; }

public required string Title { get; set; }

public string? Note { get; set; }

public ICollection<Exercise> Exercises { get; } = new List<Exercise>();
}

public class Exercise
{
[Key]
public Guid Id { get; set; }

public Guid? ExerciseVariantId { get; set; }
public ExerciseVariant ExerciseVariant { get; set; }

public string? Note { get; set; }

// Foreign keys
public Guid? WorkoutId { get; set; }
public Workout? Workout { get; set; }
}

public class ExerciseVariant
{
[Key]
public Guid Id { get; set; }

public string Name { get; set; }

public BodyPart BodyPart { get; set; }

public Category Category { get; set; }

public string? Video { get; set; }

public bool IsCustom { get; set; }

public ICollection<Exercise> Exercises { get; } = new List<Exercise>();
}
public class Workout
{
[Key]
public Guid Id { get; set; }

public required string Title { get; set; }

public string? Note { get; set; }

public ICollection<Exercise> Exercises { get; } = new List<Exercise>();
}

public class Exercise
{
[Key]
public Guid Id { get; set; }

public Guid? ExerciseVariantId { get; set; }
public ExerciseVariant ExerciseVariant { get; set; }

public string? Note { get; set; }

// Foreign keys
public Guid? WorkoutId { get; set; }
public Workout? Workout { get; set; }
}

public class ExerciseVariant
{
[Key]
public Guid Id { get; set; }

public string Name { get; set; }

public BodyPart BodyPart { get; set; }

public Category Category { get; set; }

public string? Video { get; set; }

public bool IsCustom { get; set; }

public ICollection<Exercise> Exercises { get; } = new List<Exercise>();
}
6 replies
CC#
Created by Zoli on 12/24/2024 in #help
Why event is not triggered correctly?
@SevenMgCreatine You are right it is not hit the breakpoint at all. I did not instantiated at all.
9 replies
CC#
Created by Zoli on 12/24/2024 in #help
Why event is not triggered correctly?
So somthing like WeakReferenceMessenger would be better fit for this?
9 replies
CC#
Created by Zoli on 12/16/2024 in #help
How to Filter Firebase Real-Time Data for the Logged-In User in a Maui Application?
Super, thanks. I will take a look, one question is it safe/secure to store firebase-service-account json on the Maui side?
13 replies