-3

Im getting these two errors, 1.Only assignment, call, increment, decrement, and new object expressions can be used as a statement 2.; Expected

 protected bool IsPatientAlreadyExists(String patientId)
    {
        using (CareGiverEntities dc = new CareGiverEntities())
        {

             dc.Contacts.Add(new Contact
            {
               return dc.Contacts.Any(x=> x.PatientIc==patientId);
            });
        }
        return false;

    }

i really cant see whats wrong with these codes hoping someone can enlighten me

Thibaut
  • 19
  • 10

1 Answers1

2

The problem is here:

dc.Contacts.Add(new Contact
{
    return dc.Contacts.Any(x => x.PatientIc == patientId);
});

You create Contact object but use return statement in object initializer.

Change your using to:

using (CareGiverEntities dc = new CareGiverEntities())
{
    return dc.Contacts.Any(x => x.PatientIc == patientId);
}
Roman
  • 11,966
  • 10
  • 38
  • 47