user3331421 user3331421 - 3 months ago 18
C# Question

Error with Select statement in Lambda expression

I have the following code :

getAllResult.GroupBy(g => g.OriginatingTransactionID)
.Select(r =>
{
usp_GetAll_Result getAllResult1 = r.Select(x => x).FirstOrDefault();
Bundle bundle = new Bundle
{
BundleName = getAllResult1.BundleName,
BundleStatusCode = getAllResult1.BundleStatusCode,
BundleStatusReasonCode = getAllResult1.BundleStatusReasonCode
};
}).ToList();


I am getting the error while compiling:


The type arguments for method
'System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable,
System.Func)' cannot be inferred from the usage. Try
specifying the type arguments explicitly.

Answer

.Select() returns a value. Currently you are not returning anything from your expression.

Just return your bundle.

Bundle bundle = new Bundle
                {
                    BundleName = getAllResult1.BundleName,
                    BundleStatusCode = getAllResult1.BundleStatusCode,
                    BundleStatusReasonCode = getAllResult1.BundleStatusReasonCode
                };

return bundle;