Closed
Description
Versions:
.Net 7
Redis OM 0.5.2
Model:
[Document(StorageType = StorageType.Json, Prefixes = new[] { "Lobby" })]
public class Lobby : BaseGuidEntity
{
[Indexed]
public GameType GameType { get; set; }
[Indexed(CascadeDepth = 1)]
public List<Player> Players { get; set; } = new List<Player>();
}
public class BaseGuidEntity : IEntity<Guid>
{
[RedisIdField]
[Indexed]
public Guid Id { get; set; }
[Indexed]
public DateTime CreationDate { get; set; }
public BaseGuidEntity()
{
Id = Guid.NewGuid();
CreationDate = DateTime.Now;
}
}
public class Player:BaseGuidEntity
{
[Indexed]
public long UserId { get; set; }
[Indexed]
public string? UserName { get; set; }
[Indexed]
public string? ConnectionId { get; set; }
[Indexed]
public int Order { get; set; }
}
Steps to reproduce:
- Create the model of lobby with 1 player
- Add 1 more player to the Players List and update model with UpdateAsync
public async Task<Lobby> Join(JoinLobbyViewModel model)
{
Lobby lobby = (await _lobbyRepository.GetByAsync(x => x.Id.Equals(Guid.Parse(model.GameId)))).FirstOrDefault();
if (lobby == null)
{
throw new Exception("Game is not found");
}
Player player = new Player() { ConnectionId = model.ConnectionId, UserId = model.UserId, Order = lobby.Players.Count - 1, UserName = model.UserName };
lobby.Players.Add(player);
await _lobbyRepository.UpdateAsync(lobby);
return lobby;
}
Actual result:
3 Players presented in the Players List. After any update Player list duplicating himself with adding entity additional.
Expected result:
2 Players presented in Players List. After each update Player list not duplicating himself and adding new single entity.
It works fine with
_repo = (RedisCollection)provider.RedisCollection(false)
instead of
_repo =(RedisCollection)provider.RedisCollection()
Metadata
Metadata
Assignees
Labels
No labels