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

Select<T>(x => x.ExplicitSql(text)) transform in Select statements #1926

Closed
rwasef1830 opened this issue Oct 12, 2021 · 4 comments
Closed

Select<T>(x => x.ExplicitSql(text)) transform in Select statements #1926

rwasef1830 opened this issue Oct 12, 2021 · 4 comments

Comments

@rwasef1830
Copy link
Contributor

rwasef1830 commented Oct 12, 2021

In some cases it maybe desirable to express a projection to a property that Marten's LINQ provider is unable to parse (yet).
In such case it would be so nice if we could have something like

session.Query<User>(x => new 
{ 
    Id = x.Id, 
    FirstRoleId = Projection.For<Guid>("d.data->'RoleIds'->>0") 
});

or maybe

session.Query<User>(x => new 
{ 
    Id = x.Id, 
    FirstRoleId = x.SqlProjection<Guid>("d.data->'RoleIds'->>0") 
});

A certain convention will need to be established and documented perhaps for inner subqueries or related document fetches (where the "d" alias would perhaps differ).

@rwasef1830
Copy link
Contributor Author

rwasef1830 commented Oct 12, 2021

There seems to be a deep assumption in Marten that raw sql can only be used for Where clauses or full queries only. This needs to be changed (surgery).

@davidjamesb
Copy link
Contributor

Something like this would be a very useful addition. I currently need to use 'lag' and 'lead' windowing functions and currently it seems my only option is to pass a SQL string verbatim.

@jeremydmiller jeremydmiller added this to the 7.0.0 milestone Sep 8, 2023
@jeremydmiller jeremydmiller changed the title Need something like MatchesSql but for Select projections Select<T>(x => x.ExplicitSql(text)) transform in Select statements Dec 21, 2023
@jeremydmiller
Copy link
Member

jeremydmiller commented Dec 21, 2023

Working on this one today

Tasks

  • Test with Select(x => x.ExplicitSql()) for scalar values
  • Test with Select(x => new Persion{Name = x.ExplicitSql()})

@jeremydmiller
Copy link
Member

Boom! Working locally.

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

No branches or pull requests

4 participants