Skip to content

Commit

Permalink
Treat the Identity Field as a Duplicated Field (#2016)
Browse files Browse the repository at this point in the history
Treat the Identity Field as a Duplicated Field

* Add unit test
* Treat IdField as DuplicatedField in SimpleEqualsParser
  • Loading branch information
Spotlight-Zachary authored Jan 6, 2022
1 parent 76e00b7 commit 51e6e0e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
38 changes: 38 additions & 0 deletions src/Marten.Testing/Linq/Bug_id_field_does_not_hit_id_column.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Linq;
using Marten.Linq;
using Marten.Services;
using Marten.Testing.Documents;
using Marten.Testing.Harness;
using Shouldly;
using Xunit;

namespace Marten.Testing.Linq
{
[SelectionStoryteller]
public class Bug_id_field_does_not_hit_id_column: IntegrationContextWithIdentityMap<NulloIdentityMap>
{
[Fact]
public void return_the_correct_number_of_results()
{
var target = new Target
{
Id = System.Guid.NewGuid()
};

theStore.BulkInsert(new[] { target });

var queryable = theSession.Query<Target>()
.Where(x => x.Id == target.Id);

var cmd = queryable.ToCommand(FetchType.FetchMany);

SpecificationExtensions.ShouldContain(cmd.CommandText, "where d.id = :arg0");

queryable.ToArray().Length.ShouldBe(1);
}

public Bug_id_field_does_not_hit_id_column(DefaultStoreFixture fixture) : base(fixture)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public IWhereFragment Parse(IQueryableDocument mapping, ISerializer serializer,

var useContainment = mapping.PropertySearching == PropertySearching.ContainmentOperator || field.ShouldUseContainmentOperator();

var isDuplicated = (mapping.FieldFor(members) is DuplicatedField);
var isDuplicated = field is DuplicatedField || field is IdField;
var isEnumString = field.MemberType.GetTypeInfo().IsEnum && serializer.EnumStorage == EnumStorage.AsString;

if (useContainment &&
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Linq/Parsing/SimpleEqualsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public IWhereFragment Parse(IQueryableDocument mapping, ISerializer serializer,

if (_supportContainment && ((mapping.PropertySearching == PropertySearching.ContainmentOperator ||
field.ShouldUseContainmentOperator()) &&
!(field is DuplicatedField)))
!(field is DuplicatedField || field is IdField)))
{
var dict = new Dictionary<string, object>();
ContainmentWhereFragment.CreateDictionaryForSearch(dict, expression, valueToQuery, serializer);
Expand Down

0 comments on commit 51e6e0e

Please sign in to comment.