public class ExampleSpecification : DefaultSpecification<ExampleModel>
{
public ExampleSpecification() =>
Query
.Where(q => q.Category == "Red");
}
Main.cs
var queryResult = await _cosmosRepository.QueryAsync(new ExampleSpecification());
Console Logged Expected Query
"SELECT TOP 25 VALUE root FROM root WHERE (root[\"category\"] = \"Red\")"
Console Logged Actual Query
"SELECT TOP 25 VALUE root FROM root WHERE (((NOT IS_DEFINED(root[\"type\"])) OR (root[\"type\"] = \"ExampleModel\")) AND (root[\"category\"] = \"Red\"))"
In my case I need to retrieve all "Red" objects in the given collection as "ExampleModel"s, but all of my models are stored as type "OtherModel". The actual query requires "type" exactly match "ExampleModel" or is not defined. So when executed, the actual query does not retrieve anything.
Environment summary
SDK Version: 8.1.5
OS Version: Windows
To test, in DefaultRepository.Specs I replaced repositoryExpressionProvider.Default<TItem>() with repositoryExpressionProvider.Build<TItem>(_ => true) and produced the expected query. The popper way to fix this would probably be fixing Default() in the ExpressionProvider to work more similarly to Build().
Configuring a Repository ContainerOptions with
.WithoutStrictTypeChecking()
STILL appends type checking to specification queriesReproducing The Issue
Main.cs
Console Logged Expected Query
Console Logged Actual Query
In my case I need to retrieve all "Red" objects in the given collection as "ExampleModel"s, but all of my models are stored as type "OtherModel". The actual query requires "type" exactly match "ExampleModel" or is not defined. So when executed, the actual query does not retrieve anything.
Environment summary SDK Version: 8.1.5 OS Version: Windows
Additional context This is the case since DefaultRepository.Specs uses DefaultRepositoryExpressionProvider.Default() which does not check UseStrictTypeChecking like Build() does for other DefaultRepository Operations.
To test, in DefaultRepository.Specs I replaced
repositoryExpressionProvider.Default<TItem>()
withrepositoryExpressionProvider.Build<TItem>(_ => true)
and produced the expected query. The popper way to fix this would probably be fixing Default() in the ExpressionProvider to work more similarly to Build().