troubleshooting Question

linq syntax error

Avatar of lulu50
lulu50Flag for United States of America asked on
.NET MVC* ASP .NET MVC 5.NET ProgrammingC#LINQ Query
11 Comments1 Solution23 ViewsLast Modified:
Hi,

all I want to do is select FromDate value and store it in the FromDate parameter.

I can't fix my error.

the error is in this linq
 
 FromDate = (service.Certifications?.ToList()
                                   .Where(cert => IsServiceCertificationStatusValid(cert, umCase) && !cert.FromDate.IsNull && Enumerable.Range(1, 365).Contains(aPayload.PayloadData.CurrentCaseStartDate.ToDateTime().Date.Subtract(cert.FromDate.Value).Days))
                                   .Select(cert => (DateTime)cert.FromDate?.Value)) ?? null;

Severity   Code   Description   Project   File   Line   Suppression State
Error   CS0266   Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<System.DateTime>' to 'BusinessRulesServer.BusinessObjectModel.NullableDateTime'. An explicit conversion exists (are you missing a cast?)   

I don't know how to fix that error. 
I just want to get the FromDate field from that linq. 



NullableDateTime FromDate = null;
        

                G.FnLogEvent($"{aQuestionnaireName}: Current Case Start Date {aPayload.PayloadData.CurrentCaseStartDate.ToDateTime().Date}");

                aPayload.Member.Cases?.ToList().ForEach(umCase =>
                {
                    umCase.Services?.ToList().ForEach(service =>
                    {
                        if (service.ProcedureCode != null && G.FnIsCodeContainedInProcedureCodeGroup(service.ProcedureCode.Code, aQuestionnaireName))
                        {
                            FromDate = (service.Certifications?.ToList()
                                   .Where(cert => IsServiceCertificationStatusValid(cert, umCase) && !cert.FromDate.IsNull && Enumerable.Range(1, 365).Contains(aPayload.PayloadData.CurrentCaseStartDate.ToDateTime().Date.Subtract(cert.FromDate.Value).Days))
                                   .Select(cert => (DateTime)cert.FromDate?.Value)) ?? null;
                        }
                    });
                });

Thanks,
Lulu


ASKER CERTIFIED SOLUTION
it_saige
Developer
Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros