I have this error: "Cannot implicitly convert type 'bool' to 'system.threading.tasks.task bool'" in my service implementation code. Could you correct my code please.
public Task<bool> login(string usn, string pwd) { DataClasses1DataContext auth = new DataClasses1DataContext(); var message = from p in auth.Users where p.usrName == usn && p.usrPass == pwd select p; if (message.Count() > 0) { return true; } else { return false; } }
You need to be specific whether you want this operation happen asynchronously or not.
As an example for Async Operation
:
public async Task<bool> login(string usn, string pwd) { DataClasses1DataContext auth = new DataClasses1DataContext(); var message = await (from p in auth.Users where p.usrName == usn && p.usrPass == pwd select p); if (message.Count() > 0) { return true; } else { return false; } }
If you don't need it to be an Async operation, try this:
public bool login(string usn, string pwd) { DataClasses1DataContext auth = new DataClasses1DataContext(); var message = from p in auth.Users where p.usrName == usn && p.usrPass == pwd select p; if (message.Count() > 0) { return true; } else { return false; } }
Note: async
and await
are compatible with .net 4.5 and C# 5.0 and more
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