Thibaut Thibaut - 4 years ago 95
ASP.NET (C#) Question

Only assignment, call, increment, decrement, and new object expressions can be used as a statement error when no error(Closed)

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

Answer Source

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);
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download