Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,35 @@ Prompted by the need for an easy-to-use database access component which prevents

Instead of

public User FindUserByEmail(string email)
{
User user = null;
using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Default"].ConnectionString))
using (var command = new SqlCommand("select id, email, hashed_password, salt from users where email = @email", connection))
```cs
public User FindUserByEmail(string email)
{
User user = null;
using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Default"].ConnectionString))
using (var command = new SqlCommand("select id, email, hashed_password, salt from users where email = @email", connection))
{
command.Parameters.Add("@email", SqlDbType.NVarChar, 50).Value = form.Email);
connection.Open();
using (var reader = command.ExecuteReader())
{
command.Parameters.Add("@email", SqlDbType.NVarChar, 50).Value = form.Email);
connection.Open();
using (var reader = command.ExecuteReader())
if (reader.Read())
{
if (reader.Read())
{
user = new User {Id = reader.GetInt32(0), Email = reader.GetString(1), Password = reader.GetString(2), salt = reader.GetString(3)};
}
user = new User {Id = reader.GetInt32(0), Email = reader.GetString(1), Password = reader.GetString(2), salt = reader.GetString(3)};
}
}
return user;
}
return user;
}
```

why not just write

public User FindUserByEmail(string email)
{
return Database.Open().Users.FindAllByEmail(email).FirstOrDefault();
}
```cs
public User FindUserByEmail(string email)
{
return Database.Open().Users.FindAllByEmail(email).FirstOrDefault();
}
```

and take the rest of the morning off?

Expand Down