I'm trying to grab the first user from a SQL database using Entity model that is talking to a already existing database that has a userID of the user I am looking for. This and a second error appear.
Cannot convert lambda expression to delegate type
System.Func<iomnientitylibrary.user,bool>because some of the return types in the block are not implicitly convertible to the delegate return type.
Cannot implicitly convert type int to bool.
public user GetUser(int userID)
{
using (var context = new iomniEntities())
{
user u = context.users.FirstOrDefault(user => user.userID);
return u;
}
}
context.users.ToList() is working properly but I don't want to be that inefficient.
ToListhere (that will not change the types required for subsequent Enumerable calls). This error is a compile-time type-error. Look at the expression/line with the "red squiggles". In particular,user => user.userIDdoes not return a boolean value which is what the error is trying to say. (Not using ToList in certain EF scenarios is may lead to runtime errors, which are different than compile-time type-errors: it would not fix this issue.)