Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/DocumentDbTests/Bugs/Bug_PR_3702_list_index_compile_error.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Marten;
using Marten.Linq.MatchesSql;
using Marten.Schema;
using Marten.Testing.Harness;
using NpgsqlTypes;
using Weasel.Postgresql.Tables;
using Xunit;

namespace DocumentDbTests.Bugs;

public class Bug_PR_3702_list_index_compile_error : BugIntegrationContext
{
[Fact]
public async Task can_create_array_duplicate_column_on_a_list_field()
{
StoreOptions(opts =>
{
opts.RegisterDocumentType<DocWithIndexOnList>();
});

await theStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync();

var newDoc = new DocWithIndexOnList { Id = Guid.NewGuid(), ListOfStrings = ["foo", "bar", "baz"] };
theSession.Store(newDoc);
await theSession.SaveChangesAsync();

List<string> arrayFilter = ["foo", "baz"];
var queriedDoc = await theSession.Query<DocWithIndexOnList>()
.Where(x => x.MatchesSql("d.list_of_strings @> ?", arrayFilter))
.FirstOrDefaultAsync();

Assert.Equal(newDoc.Id, queriedDoc.Id);
}

public class DocWithIndexOnList
{
public Guid Id { get; set; }

[DuplicateField(DbType = NpgsqlDbType.Array | NpgsqlDbType.Text, PgType = "text[]", IndexMethod = IndexMethod.gin)]
public List<string> ListOfStrings { get; set; }
}
}


4 changes: 2 additions & 2 deletions src/Marten/Schema/Arguments/UpsertArgument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public virtual void GenerateCodeToSetDbParameterValue(GeneratedMethod method, Ge

var dbTypeString = rawMemberType!.IsArray
? $"{Constant.ForEnum(NpgsqlDbType.Array).Usage} | {Constant.ForEnum(PostgresqlProvider.Instance.ToParameterType(rawMemberType.GetElementType()!)).Usage}"
: Constant.ForEnum(DbType).Usage;
: $"({typeof(NpgsqlDbType).FullNameInCode()})({(int)DbType})";

if (rawMemberType.IsClass || rawMemberType.IsNullable() || _members.Length > 1)
{
Expand Down Expand Up @@ -179,7 +179,7 @@ public virtual void GenerateBulkWriterCodeAsync(GeneratedType type, GeneratedMet

var dbTypeString = rawMemberType.IsArray
? $"{Constant.ForEnum(NpgsqlDbType.Array).Usage} | {Constant.ForEnum(PostgresqlProvider.Instance.ToParameterType(rawMemberType.GetElementType()!)).Usage}"
: Constant.ForEnum(DbType).Usage;
: $"({typeof(NpgsqlDbType).FullNameInCode()})({(int)DbType})";


var memberPath = _members.Select(x => x.Name).Join("?.");
Expand Down
Loading