-
-
Notifications
You must be signed in to change notification settings - Fork 476
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
Strongly-typed nested class in Select() throws exception #1026
Comments
It might be related to #565 ... |
There are two things I'd like to achieve:
The first one can be achieved by using Javascript Transformations. Perhaps, it even would works if I modify the code to: sess.Query<Model>().Select(user => new
{
Id = user.Id,
Contact = new { Id = user.ContactId, Name = contact.Name }
}); However, I can't achieve the second goal of using strong types. @jeremydmiller, would you recommend to try using Dapper here? |
I don't see Dapper doing any better here. EF Core maybe. The javascript transform will still let you use strong types, as long as what JSON it returns can be deserialized into your type. |
I have met this as well. this code did not work:
This is the generated exception:
Workaround: don't use Marten's select. Use regular linq select:
I'm not exactly sure, but I think Marten is trying to project the entity against the selected resultant class and only select the fields required (instead of ALL fields) to save data transfer. I think this is hard to combine with regular transformation code. Even if it's possible to integrate, I think it would be confusing for users to use as well. Even Spring do not mix projections. See their example. They require users to explicitly use their projections in separate method constructions so that they don't have to mix projections with regular queries. |
or |
I'm afraid this one's gonna get "fixed" by adding a better exception message telling you that you can't use constructors and you'll have to use object initializers instead. |
How to return a collection of a strongly-typed class with a nested class, like below?
where
Currently, an attempt to return in
Select()
a strongly-typed nested class (like above) throws a "Sequence contains no elements" exception:The text was updated successfully, but these errors were encountered: