Joellao
Joellao
CC#
Created by Joellao on 3/20/2024 in #help
Saving state in time - "snapshot"
Hello everyone. I'm adding some gameification to a project that I'm currently working on really sporadically. Let's say we have Users and Posts. A User can have multiple Posts and one post belongs to only one user. I want to create a Leaderboard for this. Every day at 19.00 I'd like to create a Leaderboard with the User and their number of posts. Not all the users are part of a leaderboard, they need to be added to one to be calculated. How would you guys implement this? My idea was to have a Leaderboard entity class basically like this
public class LeaderBoardEntity {
[Key]
public int Id { get; set; }
public IEnumerable<UserSnapshot> { get; set; }
public DateTime CreatedAt { get; set; }
}

public class UserSnapshotEntity {
[Key]
public int Id { get; set; }
public int PostCount { get; set; }
public IEnumerable<PostEntity> { get; set; }
}
public class LeaderBoardEntity {
[Key]
public int Id { get; set; }
public IEnumerable<UserSnapshot> { get; set; }
public DateTime CreatedAt { get; set; }
}

public class UserSnapshotEntity {
[Key]
public int Id { get; set; }
public int PostCount { get; set; }
public IEnumerable<PostEntity> { get; set; }
}
This way when I retrieve a specific Leaderboard, I can see directly the amount of posts that the user has created. Another way would be to create the leaderboard and through SQL get the posts that were created <= LeaderBoardEntity.CreatedAt. Anyone thinks of anything else?
2 replies
CC#
Created by Joellao on 2/4/2024 in #help
EF Migrations 101
Hello everyone. I'm starting a new project and wanted to know why the hell are the migrations so hard to work with. I have the Database entities and a working state of the current implementation. If I need to create a new entity with some relationship it fucks up everything. The new migration is not updating the db, or it updates the DB but then it complains when inserting data that foreign key constraint is going nuts. Do you have a preferred way on how to work with this, because deleting all the migration folder and creating a new migration each time I need to add some relationship, doesn't seem the way to deal with this. Do you guys also set the relationships in the OnModelCreating or you just let ef handle that? Question and ranting at the same time, sorry for that
27 replies
CC#
Created by Joellao on 1/24/2024 in #help
✅ Database Scaffolding going wrong.
Hello all, reading the title you can imagine what I want to ask today. Using efcore to add migrations and scaffold the tables. I have this relationship
public class UserEntity : IdentityUser<int> {
public string Firstname { get; set; }
public string Lastname { get; set; }
public string Bio { get; set; } = string.Empty;
public IEnumerable<PostEntity> Posts { get; set; }
public IEnumerable<GroupEntity> CreatedGroups { get; set; }
public IEnumerable<GroupEntity> ParticipatingGroups { get; set; }
}

public class GroupEntity{
[Key]
public int Id { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
public int CreatorId { get; set; }
public UserEntity Creator { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public bool IsPrivate { get; set; }
public IEnumerable<UserEntity> Members { get; set; }
}

public class UserGroupEntity {
[Key]
public int Id { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
public int CreatorId { get; set; }
public UserEntity Creator { get; set; }
public int UserId { get; set; }
public UserEntity User { get; set; }
public int GroupId{ get; set; }
public GroupEntity Group { get; set; }
}

protected override void OnModelCreating(ModelBuilder modelBuilder) {
base.OnModelCreating(modelBuilder);
modelBuilder
.Entity<GroupEntity>()
.HasOne(p => p.Creator)
.WithMany(u => u.CreatedGroups)
.HasForeignKey(p => p.CreatorId);

modelBuilder
.Entity<GroupEntity>()
.HasMany(e => e.Members)
.WithMany(e => e.ParticipatingGroups)
.UsingEntity<UserGroupEntity>();
}
public class UserEntity : IdentityUser<int> {
public string Firstname { get; set; }
public string Lastname { get; set; }
public string Bio { get; set; } = string.Empty;
public IEnumerable<PostEntity> Posts { get; set; }
public IEnumerable<GroupEntity> CreatedGroups { get; set; }
public IEnumerable<GroupEntity> ParticipatingGroups { get; set; }
}

public class GroupEntity{
[Key]
public int Id { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
public int CreatorId { get; set; }
public UserEntity Creator { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public bool IsPrivate { get; set; }
public IEnumerable<UserEntity> Members { get; set; }
}

public class UserGroupEntity {
[Key]
public int Id { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
public int CreatorId { get; set; }
public UserEntity Creator { get; set; }
public int UserId { get; set; }
public UserEntity User { get; set; }
public int GroupId{ get; set; }
public GroupEntity Group { get; set; }
}

protected override void OnModelCreating(ModelBuilder modelBuilder) {
base.OnModelCreating(modelBuilder);
modelBuilder
.Entity<GroupEntity>()
.HasOne(p => p.Creator)
.WithMany(u => u.CreatedGroups)
.HasForeignKey(p => p.CreatorId);

modelBuilder
.Entity<GroupEntity>()
.HasMany(e => e.Members)
.WithMany(e => e.ParticipatingGroups)
.UsingEntity<UserGroupEntity>();
}
23 replies
CC#
Created by Joellao on 12/13/2023 in #help
✅ Ubuntu + Dotnet
Is anyone using Linux Ubuntu and dotnet? I can't seem to install any version, or rather I can install it, create project with it and whatever, but when Nuget seems to be involved it gets stuck for 10 or so minutes and then it fails with FatalProtocolException . Has anyone any clue on how to solve this? I can access https://api.nuget.org/v3/index.json through my browser and also curl perfectly fine Tried it through ubuntu apt repository (dotnet 7), microsoft repository (dotnet 8) and also the dotnet-install script. All same thing
31 replies
CC#
Created by Joellao on 8/19/2022 in #help
Geometric operations in the cartesian plan
Hello everyone. I have to implement a few tasks and some of that are quite easy to understand (and to implement) 1) Definition of a Line by means of Two Points (Created class Point with x,y, and the class TwoPointLine that has this two points) 2) Definition of a line by means of gradient and y-intercept (For what I understand is the y=mx+c formula. But should I consider only m and c on this class or also x being passed as a point) 3)Condititons on parallelism etc. (Done) Now what I've done is creating an Interface called Line and the two definitions will implement such interface with methods like (GetSlop(), isParallel etc.) Since the same formula is used for isParallel and the other definitions, I implemented them as default in the Interface (Don't know if I did right on this)... The main thing that I'm asking is for point 2, if in your opinion I should pass also X as an argument to the constructor, or not. Or maybe i'm completely off and I misunderstood that line... Not asking for the code, just to understand a little bit more.
1 replies