In this image I have three relevant columns, AllowedInvites
, FilteredWords
, and FilteredRegexes
. They are all of type List<string>
. I am calling this method.
public async Task AddWordsToFilter(ulong guildId, params string[] words)
{
var guild = await _kinaContext
.Guilds
.AsQueryable()
.FirstOrDefaultAsync(x => x.GuildId == guildId);
foreach (var word in words)
{
if (guild.FilteredWords.Contains(word))
{
continue;
}
guild.FilteredWords.Add(word);
}
await _kinaContext.SaveChangesAsync();
}
This should only add the words
to the FilteredWords
column. However, as per the screenshot, it is added to the other two columns also.
If I try to remove, it works as expected. This issue only occurs on add.
I am using Postgres.
Please help I am dumbfounded.
Guild
class
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Kinabot.Modules
{
public class Guild
{
[Key]
public int Id { get; set; }
[Required]
public ulong GuildId { get; init; }
[Required]
public ulong MessageLogChannelId { get; set; }
[Required]
public ulong InfractionLogChannelId { get; set; }
[Required]
public bool AllowsInvites { get; set; }
public List<string> AllowedInvites { get; set; } = new();
public bool Filter { get; set; }
public List<string> FilteredWords { get; set; } = new();
public List<string> FilteredRegexes { get; set; } = new();
public ulong MuteRoleId { get; set; }
}
public class GuildConfiguration : IEntityTypeConfiguration<Guild>
{
public void Configure(EntityTypeBuilder<Guild> builder)
{
builder
.Property(x => x.GuildId)
.HasConversion<long>();
builder
.Property(x => x.MessageLogChannelId)
.HasConversion<long>();
builder
.Property(x => x.InfractionLogChannelId)
.HasConversion<long>();
builder
.Property(x => x.MuteRoleId)
.HasConversion<long>();
builder
.HasIndex(x => x.GuildId)
.IsUnique();
}
}
}