I'm trying to make this work :
 var customerSearchResult = customers.GroupBy(                               
            x => new {
                x.CustomerID,
                x.email,
                x.CreatedOn,
                x.FirstName,
                x.LastName,
                x.Profile == null ? -1 : x.Profile.Value
            })
            .Select(csr => new CustomerSearchResult
            {
                CustomerID = csr.Key.CustomerID,
                Email = csr.Key.email,
                CreatedOn = csr.Key.CreatedOn
            });
I am getting an
Error CS0746 Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.
Because of this line x.Profile == null ? -1 : x.Profile.Value
Profile can be null.
Any idea how to do this?
Declare name for this variable in Anonymous class:
var customerSearchResult = customers.GroupBy(                               
            x => new {
                x.CustomerID,
                x.email,
                x.CreatedOn,
                x.FirstName,
                x.LastName,
                Profile = x.Profile == null ? -1 : x.Profile.Value
            })
            .Select(csr => new CustomerSearchResult
            {
                CustomerID = csr.Key.CustomerID,
                Email = csr.Key.email,
                CreatedOn = csr.Key.CreatedOn
            });
As @Abion47 mentioned in comment, you could simplify your assihnment as:
Profile = x.Profile?.Value ?? -1
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With