Skip to content
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

Allow using Guid and other types for queries #274

Open
olee opened this issue Oct 6, 2019 · 1 comment
Open

Allow using Guid and other types for queries #274

olee opened this issue Oct 6, 2019 · 1 comment

Comments

@olee
Copy link

olee commented Oct 6, 2019

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:

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

The generated query is explicitly performing an array mapping with the to-string function:

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:

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

teamCtx.Query<Team>().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:

teamCtx.Query<Team>().UseKeys(u.Teams.Cast<string>()).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?

@MikeGoldsmith
Copy link
Contributor

Hi @olee

Thanks for the information, we'll look into if there is a work around or another solution is possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants