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

FlatTable's.Map on a nested event property generates null-conditional member access resulting in compilation error #3643

Open
migajek opened this issue Jan 26, 2025 · 2 comments

Comments

@migajek
Copy link
Contributor

migajek commented Jan 26, 2025

Please consider the following event:

public record MyEvent(Guid Id, ExtCompKey ItemId);

where ExtCompKey is a struct: public record struct ExtCompKey(string Identifier, int Key);

now when I try to Map it in the flat table projection:

Project<MyEvent>(m =>
{
    m.Map(x => x.ItemId.Key);
});

the code generation throws

System.InvalidOperationException: Compilation failures!

CS0023: Operator '?' cannot be applied to operand of type 'ExtCompKey'
...
case Marten.Events.IEvent<(redacted).MyEvent> event_MyEvent112:
                    operations.QueueSqlCommand("select public.mt_upsert_test1_myevent(?, ?);", event_MyEvent112.StreamId,
event_MyEvent112.Data.ItemId?.Key);
                    break;

the only workaround I found so far is to enrich the event with a direct accessor (public int ItmKey => ItemId.Key;) and use it in the Map expression

@migajek migajek changed the title Map on a nested event property generates null-conditional member access resulting in compilation error FlatTable's.Map on a nested event property generates null-conditional member access resulting in compilation error Jan 26, 2025
@jeremydmiller
Copy link
Member

@migajek Happy to take a PR for this one if you want to dive in. Might not be that bad.

@migajek
Copy link
Contributor Author

migajek commented Jan 28, 2025

will look into it :)

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