couchbaselabs / couchbaselabs/Linq2Couchbase

Allow using Guid and other types for queries

Open
#274 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
98
Forks
50
PR merge metrics
No merged PRs in 30d

Description

I'm writing an application where I have many related entities and I use Guid most of the time as key type.
However, this causes a lot of issues with queries like the following:

```c#
var userData = userCtx.Query()
.UseKeys(new string[] { userId.ToString() })
.Select(u => new
{
User = u,
Teams = teamCtx.Query().UseKeys(u.Teams.Select(x => x.ToString())).ToList(),
Groups = groupCtx.Query().UseKeys(u.Groups.Select(x => x.ToString())).ToList(),
})
.FirstOrDefault();
```

The generated query is explicitly performing an array mapping with the to-string function:
```sql
SELECT
`Extent1` as `user`,
(SELECT RAW `Extent2` FROM `team` as `Extent2` USE KEYS ARRAY TOSTRING(`Extent3`) FOR `Extent3` IN `Extent1`.`teams` END) as `teams`,
(SELECT RAW `Extent4` FROM `group` as `Extent4` USE KEYS ARRAY TOSTRING(`Extent5`) FOR `Extent5` IN `Extent1`.`groups` END) as `groups`
FROM `user` as `Extent1` USE KEYS ['00000000-0000-0000-0001-000000000001']
LIMIT 1
```
Instead, the query I would expect to get should look like this:

```sql
SELECT
`Extent1` as `user`,
(SELECT RAW `Extent2` FROM `team` as `Extent2` USE KEYS `Extent1`.`teams`) as `teams`,
(SELECT RAW `Extent4` FROM `group` as `Extent4` USE KEYS `Extent1`.`groups`) as `groups`
FROM `user` as `Extent1` USE KEYS ['00000000-0000-0000-0001-000000000001']
LIMIT 1
```

Instead I would like to be able to either directly write
```c#
teamCtx.Query().UseKeys(u.Teams).ToList()
```
or at least be able to use the Linq cast function like this to make it compile properly and generate an efficient query:
```c#
teamCtx.Query().UseKeys(u.Teams.Cast()).ToList()
```

However this last variant is throwing an error: `No coercion operator is defined between types 'System.Guid' and 'System.String'.`

Is there any other way to achieve the query I intended or would this require an adjustment to this library?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.