what this method will return when the db is null for some reason? compile is fine and there is no return statement outside the using block.
public Guid GetUserId(string username)
{
using (AndeDBEntities db = new AndeDBEntities())
{
var userId =
from u in db.Users
where u.Username == username
&& u.Deleted != true
select new { UserID = u.UserId };
if (userId == null || userId.Count() == 0)
return Guid.Empty;
else
return userId.First().UserID;
}
}
If the
dbis null for some reason, this will likely raise an Exception at runtime. This will most likely be a NullReferenceException, but could be some other exception depending on how it was written.However, this really shouldn’t be possible.
dbshould always be valid, although db.Users may be null if the constructor (AndeDBEntities) doesn’t set it properly. In this case, you’ll get a NullReferenceException when you hit your LINQ query (ie: accessingdb.Users).