Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
sheryever authored Nov 4, 2016
1 parent 2aec973 commit b5c2365
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,37 @@ SimpleAccess implementaion for Sql Server.
Reading single record from the database as dynamic object
``` C#
ISqlSimpleAccess simpleAccess = new SqlSimpleAccess("defaultConnection");
var person = simpleAccess.ExecuteDynamic("Select * FROM people where id = @id;", new { id = 12});
var person = simpleAccess.ExecuteDynamic("SELECT * FROM dbo.People where id = @id;", new { id = 12});
```

Reading records from the database as IEnumerable<dynamic>
``` C#
ISqlSimpleAccess simpleAccess = new SqlSimpleAccess("defaultConnection");
var people = simpleAccess.ExecuteDynamic("Select * FROM people;");
var people = simpleAccess.ExecuteDynamic("SELECT * FROM dbo.People;");
```

Reading single record from the database as Person object
``` C#
ISqlSimpleAccess simpleAccess = new SqlSimpleAccess("defaultConnection");
var person = simpleAccess.ExecuteEntity<Person>("Select * FROM people where id = @id;", new { id = 12});
var person = simpleAccess.ExecuteEntity<Person>("SELECT * FROM dbo.People where id = @id;", new { id = 12});
```

Reading records from the database as IEnumerable&lt;Person&gt;
``` C#
ISqlSimpleAccess simpleAccess = new SqlSimpleAccess("defaultConnection");
var people = simpleAccess.ExecuteEntities<Person>("Select * FROM people;");
var people = simpleAccess.ExecuteEntities<Person>("SELECT * FROM dbo.People;");
```

Reading records from the database using DataReader
``` C#
ISqlSimpleAccess simpleAccess = new SqlSimpleAccess("defaultConnection");
var dataReader = simpleAccess.ExecuteReader("Select * FROM people;");
var dataReader = simpleAccess.ExecuteReader("SELECT * FROM dbo.People;");
```

Executing aggregate query using SimpleAccess
``` C#
ISqlSimpleAccess simpleAccess = new SqlSimpleAccess("defaultConnection");
var totalPeople = simpleAccess.ExecuteScalar<int>("Select COUNT(*) FROM people;");
var totalPeople = simpleAccess.ExecuteScalar<int>("SELECT COUNT(*) FROM dbo.People;");
```

Executes a SQL statement against the connection and returns the number of rows affected
Expand All @@ -78,9 +78,9 @@ public class PersonInsertViewModel
ISqlSimpleAccess simpleAccess = new SqlSimpleAccess("defaultConnection");

var person = new PersonInsertViewModel {Name = "Ahmed", Address = "Madina"};
var rowAffected = simpleAccess.ExecuteNonQuery("INSERT INTO People values (@name, @address);", person);
var rowAffected = simpleAccess.ExecuteNonQuery("INSERT INTO dbo.People values (@name, @address);", person);

var rowAffected = simpleAccess.ExecuteNonQuery("UPDATE People SET Name=@name WHERE Id = @id;", new {id = 1, name = "Muhammad"});
var rowAffected = simpleAccess.ExecuteNonQuery("UPDATE dbo.People SET Name=@name WHERE Id = @id;", new {id = 1, name = "Muhammad"});

```

Expand All @@ -94,7 +94,7 @@ try
{
var person = new Person() { Name = "Ahmed", Address = "Madina" };

var newId = simpleAccess.ExecuteScalar<int>(transaction, "INSERT INTO People VALUES (@name, @Address); SELECT SCOPE_IDENTITY();", person);
var newId = simpleAccess.ExecuteScalar<int>(transaction, "INSERT INTO dbo.People VALUES (@name, @Address); SELECT SCOPE_IDENTITY();", person);

simpleAccess.EndTransaction(transaction);
}
Expand Down

0 comments on commit b5c2365

Please sign in to comment.