-
-
Notifications
You must be signed in to change notification settings - Fork 534
New Test for IQueryPlanning and filtering with string collection #4202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+54
−0
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/LinqTests/Bugs/compiled_query_problem_with_search_by_string_and_string_collections.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Linq.Expressions; | ||
| using System.Threading.Tasks; | ||
| using Marten; | ||
| using Marten.Linq; | ||
| using Marten.Testing.Documents; | ||
| using Marten.Testing.Harness; | ||
| using Shouldly; | ||
|
|
||
| namespace LinqTests.Bugs; | ||
|
|
||
| public class compiled_query_problem_with_search_by_string_and_string_collections(DefaultStoreFixture fixture): IntegrationContext(fixture) | ||
| { | ||
| protected override async Task fixtureSetup() | ||
| { | ||
| await theStore.Advanced.ResetAllData(); | ||
| } | ||
|
|
||
| public class IssuesByTitles: ICompiledListQuery<Issue>, IQueryPlanning | ||
| { | ||
| [Marten.Events.CodeGeneration.MartenIgnore] | ||
| public required string[] Titles { get; set; } | ||
| public required string Status { get; set; } | ||
|
|
||
| public Expression<Func<IMartenQueryable<Issue>, IEnumerable<Issue>>> QueryIs() | ||
| { | ||
| return query => query.Where(x => x.Status == Status && x.Title.IsOneOf(Titles)); | ||
| } | ||
| void IQueryPlanning.SetUniqueValuesForQueryPlanning() | ||
| { | ||
| Status = "status"; | ||
| Titles = ["title"]; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it seems that the issue is in code generation when IQueryPlanning is used. It produces valid sql and parameters, but it does not use the value from the public override void ConfigureCommand(Weasel.Postgresql.ICommandBuilder builder, Marten.Internal.IMartenSession session)
{
var parameters1 = builder.AppendWithParameters(@"select d.data from public.mt_doc_issue as d where (d.data ->> 'Status' = ^ and d.data ->> 'Title' = ANY(^));", '^');
parameters1[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text;
parameters1[0].Value = _query.Status;
parameters1[1].Value = new string[]{"title"}; // <---- here is the constant instead of _query.Titles
parameters1[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Array | NpgsqlTypes.NpgsqlDbType.Varchar;
}if i edit it manually to |
||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task can_search_isOneOf_strings_with_compiled_queries_and_query_planning() | ||
| { | ||
| var issue1 = new Issue { Title = "Issue1", Status = "Open" }; | ||
| var issue2 = new Issue { Title = "Issue2", Status = "Open"}; | ||
| var issue3 = new Issue { Title = "Issue3", Status = "Open" }; | ||
|
|
||
| theSession.Store(issue1, issue2, issue3); | ||
| await theSession.SaveChangesAsync(); | ||
|
|
||
| await using var session = theStore.QuerySession(); | ||
| var query = new IssuesByTitles { Titles = [issue1.Title, issue2.Title], Status = issue1.Status }; | ||
| var issues = await session.QueryAsync(query); | ||
|
|
||
| issues.Count().ShouldBe(2); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm not sure if this should be used or not. without this attribute it throws an exception because it tries to use undrying type (
string) as document type