diff --git a/Readme.md b/Readme.md index 3fb05fe6b..f6733fc74 100644 --- a/Readme.md +++ b/Readme.md @@ -4,9 +4,22 @@ Dapper - a simple object mapper for .Net Release Notes ------------- - Located at [stackexchange.github.io/Dapper](https://stackexchange.github.io/Dapper/) +Packages +-------- + +MyGet Pre-release feed: https://www.myget.org/gallery/dapper + +| Package | NuGet Stable | NuGet Pre-release | Downloads | MyGet | +| ------- | ------------ | ----------------- | --------- | ----- | +| [Dapper](https://www.nuget.org/packages/Dapper/) | [![Dapper](https://img.shields.io/nuget/v/Dapper.svg)](https://www.nuget.org/packages/Dapper/) | [![Dapper](https://img.shields.io/nuget/vpre/Dapper.svg)](https://www.nuget.org/packages/Dapper/) | [![Dapper](https://img.shields.io/nuget/dt/Dapper.svg)](https://www.nuget.org/packages/Dapper/) | [![Dapper MyGet](https://img.shields.io/myget/dapper/vpre/Dapper.svg)](https://www.myget.org/feed/dapper/package/nuget/Dapper) | +| [Dapper.Contrib](https://www.nuget.org/packages/Dapper.Contrib/) | [![Dapper.Contrib](https://img.shields.io/nuget/v/Dapper.Contrib.svg)](https://www.nuget.org/packages/Dapper.Contrib/) | [![Dapper.Contrib](https://img.shields.io/nuget/vpre/Dapper.Contrib.svg)](https://www.nuget.org/packages/Dapper.Contrib/) | [![Dapper.Contrib](https://img.shields.io/nuget/dt/Dapper.Contrib.svg)](https://www.nuget.org/packages/Dapper.Contrib/) | [![Dapper.Contrib MyGet](https://img.shields.io/myget/dapper/vpre/Dapper.Contrib.svg)](https://www.myget.org/feed/dapper/package/nuget/Dapper.Contrib) | +| [Dapper.EntityFramework](https://www.nuget.org/packages/Dapper.EntityFramework/) | [![Dapper.EntityFramework](https://img.shields.io/nuget/v/Dapper.EntityFramework.svg)](https://www.nuget.org/packages/Dapper.EntityFramework/) | [![Dapper.EntityFramework](https://img.shields.io/nuget/vpre/Dapper.EntityFramework.svg)](https://www.nuget.org/packages/Dapper.EntityFramework/) | [![Dapper.EntityFramework](https://img.shields.io/nuget/dt/Dapper.EntityFramework.svg)](https://www.nuget.org/packages/Dapper.EntityFramework/) | [![Dapper.EntityFramework MyGet](https://img.shields.io/myget/dapper/vpre/Dapper.EntityFramework.svg)](https://www.myget.org/feed/dapper/package/nuget/Dapper.EntityFramework) | +| [Dapper.EntityFramework.StrongName](https://www.nuget.org/packages/Dapper.EntityFramework.StrongName/) | [![Dapper.EntityFramework.StrongName](https://img.shields.io/nuget/v/Dapper.EntityFramework.StrongName.svg)](https://www.nuget.org/packages/Dapper.EntityFramework.StrongName/) | [![Dapper.EntityFramework.StrongName](https://img.shields.io/nuget/vpre/Dapper.EntityFramework.StrongName.svg)](https://www.nuget.org/packages/Dapper.EntityFramework.StrongName/) | [![Dapper.EntityFramework.StrongName](https://img.shields.io/nuget/dt/Dapper.EntityFramework.StrongName.svg)](https://www.nuget.org/packages/Dapper.EntityFramework.StrongName/) | [![Dapper.EntityFramework.StrongName MyGet](https://img.shields.io/myget/dapper/vpre/Dapper.EntityFramework.StrongName.svg)](https://www.myget.org/feed/dapper/package/nuget/Dapper.EntityFramework.StrongName) | +| [Dapper.Rainbow](https://www.nuget.org/packages/Dapper.Rainbow/) | [![Dapper.Rainbow](https://img.shields.io/nuget/v/Dapper.Rainbow.svg)](https://www.nuget.org/packages/Dapper.Rainbow/) | [![Dapper.Rainbow](https://img.shields.io/nuget/vpre/Dapper.Rainbow.svg)](https://www.nuget.org/packages/Dapper.Rainbow/) | [![Dapper.Rainbow](https://img.shields.io/nuget/dt/Dapper.Rainbow.svg)](https://www.nuget.org/packages/Dapper.Rainbow/) | [![Dapper.Rainbow MyGet](https://img.shields.io/myget/dapper/vpre/Dapper.Rainbow.svg)](https://www.myget.org/feed/dapper/package/nuget/Dapper.Rainbow) | +| [Dapper.SqlBuilder](https://www.nuget.org/packages/Dapper.SqlBuilder/) | [![Dapper.SqlBuilder](https://img.shields.io/nuget/v/Dapper.SqlBuilder.svg)](https://www.nuget.org/packages/Dapper.SqlBuilder/) | [![Dapper.SqlBuilder](https://img.shields.io/nuget/vpre/Dapper.SqlBuilder.svg)](https://www.nuget.org/packages/Dapper.SqlBuilder/) | [![Dapper.SqlBuilder](https://img.shields.io/nuget/dt/Dapper.SqlBuilder.svg)](https://www.nuget.org/packages/Dapper.SqlBuilder/) | [![Dapper.SqlBuilder MyGet](https://img.shields.io/myget/dapper/vpre/Dapper.SqlBuilder.svg)](https://www.myget.org/feed/dapper/package/nuget/Dapper.SqlBuilder) | +| [Dapper.StrongName](https://www.nuget.org/packages/Dapper.StrongName/) | [![Dapper.StrongName](https://img.shields.io/nuget/v/Dapper.StrongName.svg)](https://www.nuget.org/packages/Dapper.StrongName/) | [![Dapper.StrongName](https://img.shields.io/nuget/vpre/Dapper.StrongName.svg)](https://www.nuget.org/packages/Dapper.StrongName/) | [![Dapper.StrongName](https://img.shields.io/nuget/dt/Dapper.StrongName.svg)](https://www.nuget.org/packages/Dapper.StrongName/) | [![Dapper.StrongName MyGet](https://img.shields.io/myget/dapper/vpre/Dapper.StrongName.svg)](https://www.myget.org/feed/dapper/package/nuget/Dapper.StrongName) | Features -------- @@ -31,8 +44,8 @@ public class Dog public float? Weight { get; set; } public int IgnoredProperty { get { return 1; } } -} - +} + var guid = Guid.NewGuid(); var dog = connection.Query("select Age = @Age, Id = @Id", new { Age = (int?)null, Id = guid }); @@ -71,12 +84,12 @@ Example usage: ```csharp var count = connection.Execute(@" - set nocount on - create table #t(i int) - set nocount off - insert #t - select @a a union all select @b - set nocount on + set nocount on + create table #t(i int) + set nocount off + insert #t + select @a a union all select @b + set nocount on drop table #t", new {a=1, b=2 }); Assert.Equal(2, count); ``` @@ -111,10 +124,10 @@ The performance tests are broken in to 3 lists: | Method | Duration | Remarks | | --------------------------------------------------- | -------- | ------- | -| Hand coded (using a `SqlDataReader`) | 47ms | +| Hand coded (using a `SqlDataReader`) | 47ms | | Dapper `ExecuteMapperQuery` | 49ms | | [ServiceStack.OrmLite](https://github.com/ServiceStack/ServiceStack.OrmLite) (QueryById) | 50ms | -| [PetaPoco](http://www.toptensoftware.com/petapoco/) | 52ms | [Can be faster](http://web.archive.org/web/20170921124755/http://www.toptensoftware.com/blog/posts/94-PetaPoco-More-Speed) | +| [PetaPoco](https://github.com/CollaboratingPlatypus/PetaPoco) | 52ms | [Can be faster](https://web.archive.org/web/20170921124755/http://www.toptensoftware.com/blog/posts/94-PetaPoco-More-Speed) | | BLToolkit | 80ms | | SubSonic CodingHorror | 107ms | | NHibernate SQL | 104ms | @@ -153,7 +166,7 @@ Parameterized queries Parameters are passed in as anonymous classes. This allow you to name your parameters easily and gives you the ability to simply cut-and-paste SQL snippets and run them in your db platform's Query analyzer. ```csharp -new {A = 1, B = "b"} // A will be mapped to the param @A, B to the param @B +new {A = 1, B = "b"} // A will be mapped to the param @A, B to the param @B ``` List Support @@ -215,7 +228,7 @@ class User Now let us say that we want to map a query that joins both the posts and the users table. Until now if we needed to combine the result of 2 queries, we'd need a new object to express it but it makes more sense in this case to put the `User` object inside the `Post` object. -This is the user case for multi mapping. You tell dapper that the query returns a `Post` and a `User` object and then give it a function describing what you want to do with each of the rows containing both a `Post` and a `User` object. In our case, we want to take the user object and put it inside the post object. So we write the function: +This is the user case for multi mapping. You tell dapper that the query returns a `Post` and a `User` object and then give it a function describing what you want to do with each of the rows containing both a `Post` and a `User` object. In our case, we want to take the user object and put it inside the post object. So we write the function: ```csharp (post, user) => { post.Owner = user; return post; } @@ -230,11 +243,11 @@ The 3 type arguments to the `Query` method specify what objects dapper should us Everything put together, looks like this: ```csharp -var sql = -@"select * from #Posts p -left join #Users u on u.Id = p.OwnerId +var sql = +@"select * from #Posts p +left join #Users u on u.Id = p.OwnerId Order by p.Id"; - + var data = connection.Query(sql, (post, user) => { post.Owner = user; return post;}); var post = data.First(); @@ -253,19 +266,19 @@ Dapper allows you to process multiple result grids in a single query. Example: ```csharp -var sql = +var sql = @" select * from Customers where CustomerId = @id select * from Orders where CustomerId = @id select * from Returns where CustomerId = @id"; - + using (var multi = connection.QueryMultiple(sql, new {id=selectedId})) { var customer = multi.Read().Single(); var orders = multi.Read().ToList(); var returns = multi.Read().ToList(); ... -} +} ``` Stored Procedures @@ -273,7 +286,7 @@ Stored Procedures Dapper fully supports stored procs: ```csharp -var user = cnn.Query("spGetUser", new {Id = 1}, +var user = cnn.Query("spGetUser", new {Id = 1}, commandType: CommandType.StoredProcedure).SingleOrDefault(); ``` @@ -285,10 +298,10 @@ p.Add("@a", 11); p.Add("@b", dbType: DbType.Int32, direction: ParameterDirection.Output); p.Add("@c", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue); -cnn.Execute("spMagicProc", p, commandType: CommandType.StoredProcedure); +cnn.Execute("spMagicProc", p, commandType: CommandType.StoredProcedure); int b = p.Get("@b"); -int c = p.Get("@c"); +int c = p.Get("@c"); ``` Ansi Strings and varchar @@ -318,9 +331,9 @@ using (var reader = connection.ExecuteReader("select * from Shapes")) var circleParser = reader.GetRowParser(typeof(Circle)); var squareParser = reader.GetRowParser(typeof(Square)); var triangleParser = reader.GetRowParser(typeof(Triangle)); - + var typeColumnIndex = reader.GetOrdinal("Type"); - + while (reader.Read()) { IShape shape; @@ -339,7 +352,7 @@ using (var reader = connection.ExecuteReader("select * from Shapes")) default: throw new NotImplementedException(); } - + shapes.Add(shape); } }