Download - Simple.Data intro slides
![Page 1: Simple.Data intro slides](https://reader035.vdocuments.us/reader035/viewer/2022081907/54b718c34a7959987b8b459e/html5/thumbnails/1.jpg)
Simple.Data.NET database access made easier
![Page 2: Simple.Data intro slides](https://reader035.vdocuments.us/reader035/viewer/2022081907/54b718c34a7959987b8b459e/html5/thumbnails/2.jpg)
ADO.NETusing (var connection = new SqlConnection(connectionString)) { using (var command = connection.CreateCommand()) {
command.CommandText = "select Id, FirstName, LastName“ + " from people where Id = @id"; command.Parameters.Add("@id", SqlDbType.Int).Value = id;
connection.Open();
using (var reader = command.ExecuteReader()) { if (reader.Read()) { return new Person { Id = reader.GetInt32(0), FirstName = reader.IsDBNull(1) ? “” : reader.GetString(1), LastName = reader.IsDBNull(2) ? “” : reader.GetString(2), };} } } }
![Page 3: Simple.Data intro slides](https://reader035.vdocuments.us/reader035/viewer/2022081907/54b718c34a7959987b8b459e/html5/thumbnails/3.jpg)
Microsoft.Data// What you should do...using (var database = Database.Open()){ var sql = "select Id, FirstName, LastName" + " from people where Id = @0";
return database.Query(sql, id);}
![Page 4: Simple.Data intro slides](https://reader035.vdocuments.us/reader035/viewer/2022081907/54b718c34a7959987b8b459e/html5/thumbnails/4.jpg)
Microsoft.Data// What PHP refugees will actually do...using (var database = Database.Open()){ var sql = "select Id, FirstName, LastName" + " from people where Id = “ + id;
return database.Query(sql);}
![Page 5: Simple.Data intro slides](https://reader035.vdocuments.us/reader035/viewer/2022081907/54b718c34a7959987b8b459e/html5/thumbnails/5.jpg)
Simple.Data
var database = Database.Open();return database.People.FindById(id);
// Easier to do it right
![Page 6: Simple.Data intro slides](https://reader035.vdocuments.us/reader035/viewer/2022081907/54b718c34a7959987b8b459e/html5/thumbnails/6.jpg)
Simple.Data……is Database agnostic
…is naming-style tolerantPascalCase, SHOUTY_CASE, snake_case
…favours Convention over Configuration
…is not an O/RM
![Page 7: Simple.Data intro slides](https://reader035.vdocuments.us/reader035/viewer/2022081907/54b718c34a7959987b8b459e/html5/thumbnails/7.jpg)
Simple CRUDdb.People.Insert(Id: 1, FirstName: “Bob”, …);
db.People.FindAllByName(“Bob”);
db.People.FindByFirstNameAndLastName(“Bob”, “X”);
db.People.UpdateById(Id: 1, FirstName: “Robert”);
db.People.DeleteById(1);
![Page 8: Simple.Data intro slides](https://reader035.vdocuments.us/reader035/viewer/2022081907/54b718c34a7959987b8b459e/html5/thumbnails/8.jpg)
Complex queries db.Find(db.Users.JoinDate >= new DateTime(2010,11,13);
db.Find(db.Posts.Comments.Approved != "Y")
db.Find(db.Users.Age >= 18 && db.Users.Age <= 35)
(Simple.Data uses operator overloading to turn these expressions into its own SimpleExpression objects)
![Page 9: Simple.Data intro slides](https://reader035.vdocuments.us/reader035/viewer/2022081907/54b718c34a7959987b8b459e/html5/thumbnails/9.jpg)
Simple O/RMvar person = db.People.FindById(1);
foreach (var telNo in person.PhoneNumbers){ if (telNo.DiallingCode.StartsWith(“07”)) { SendSpamText(telNo); }}
![Page 10: Simple.Data intro slides](https://reader035.vdocuments.us/reader035/viewer/2022081907/54b718c34a7959987b8b459e/html5/thumbnails/10.jpg)
Simple.Data……is Open Source (MIT license)
…can be downloaded from:http://github.com/markrendle/Simple.Data/
…wants to be forked, patched and loved
Mark Rendle ~ twitter.com/markrendle ~ blog.markrendle.net