From 8f6f515cfd043afffe83ea4bc02fd0428d53e61b Mon Sep 17 00:00:00 2001 From: busterwood Date: Fri, 18 Mar 2016 12:39:17 +0000 Subject: [PATCH] Rename datareader extension methods from "To..." to "Read..." to avoid conflicts with Linq extension methods names --- Mapper/CommandExtension.cs | 40 +++++++++++++++---------------- Mapper/ConnectionExtension.cs | 28 +++++++++++----------- Mapper/DataReaderExtensions.cs | 21 ++++++++-------- Mapper/Mapper.nuspec | 2 +- Mapper/Properties/AssemblyInfo.cs | 4 ++-- README.md | 20 ++++++++-------- 6 files changed, 57 insertions(+), 58 deletions(-) diff --git a/Mapper/CommandExtension.cs b/Mapper/CommandExtension.cs index dff6f0a..695f9c2 100644 --- a/Mapper/CommandExtension.cs +++ b/Mapper/CommandExtension.cs @@ -17,117 +17,117 @@ public static class DbCommandExtensions /// Executes the reading exactly one item /// when zero values read or more than one value can be read - public static T ReadSingle(this IDbCommand cmd) + public static T ExecuteSingle(this IDbCommand cmd) { Contract.Requires(cmd != null); Contract.Ensures(Contract.Result() != null); using (var reader = cmd.ExecuteReader(CommandBehavior.SingleRow)) { - return reader.Single(); + return reader.ReadSingle(); } } /// Executes the reading exactly one item /// when zero values read or more than one value can be read - public static async Task ReadSingleAsync(this SqlCommand cmd) + public static async Task ExecuteSingleAsync(this SqlCommand cmd) { Contract.Requires(cmd != null); Contract.Ensures(Contract.Result() != null); using (var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SingleRow)) { - return await reader.SingleAsync(); + return await reader.ReadSingleAsync(); } } /// Executes the reading one item /// Returns the default vaue of T if no values be read, i.e may return null - public static T ReadSingleOrDefault(this IDbCommand cmd) + public static T ExecuteSingleOrDefault(this IDbCommand cmd) { Contract.Requires(cmd != null); using (var reader = cmd.ExecuteReader(CommandBehavior.SingleRow)) { - return reader.SingleOrDefault(); + return reader.ReadSingleOrDefault(); } } /// Executes the reading one item /// Returns the default vaue of T if no values be read, i.e may return null - public static async Task ReadSingleOrDefaultAsync(this SqlCommand cmd) + public static async Task ExecuteSingleOrDefaultAsync(this SqlCommand cmd) { Contract.Requires(cmd != null); using (var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SingleRow)) { - return await reader.SingleOrDefaultAsync(); + return await reader.ReadSingleOrDefaultAsync(); } } /// Executes the and reads all the records into a list - public static List ReadList(this IDbCommand cmd) + public static List ExecuteList(this IDbCommand cmd) { Contract.Requires(cmd != null); Contract.Ensures(Contract.Result>() != null); using (var reader = cmd.ExecuteReader()) { - return reader.ToList(); + return reader.ReadList(); } } /// Executes the and reads all the records into a list - public static async Task> ReadListAsync(this SqlCommand cmd) + public static async Task> ExecuteListAsync(this SqlCommand cmd) { Contract.Requires(cmd != null); Contract.Ensures(Contract.Result>() != null); using (var reader = await cmd.ExecuteReaderAsync()) { - return await reader.ToListAsync(); + return await reader.ReadListAsync(); } } /// Executes the and reads all the records into a dictionary, using the supplied to generate the key - public static Dictionary ReadDictionary(this IDbCommand cmd, Func keyFunc) + public static Dictionary ExecuteDictionary(this IDbCommand cmd, Func keyFunc) { Contract.Requires(cmd != null); Contract.Requires(keyFunc != null); Contract.Ensures(Contract.Result>() != null); using (var reader = cmd.ExecuteReader()) { - return reader.ToDictionary(keyFunc); + return reader.ReadDictionary(keyFunc); } } /// Executes the and reads all the records into a dictionary, using the supplied to generate the key - public static async Task> ReadDictionaryAsync(this SqlCommand cmd, Func keyFunc) + public static async Task> ExecuteDictionaryAsync(this SqlCommand cmd, Func keyFunc) { Contract.Requires(cmd != null); Contract.Requires(keyFunc != null); Contract.Ensures(Contract.Result>() != null); using (var reader = await cmd.ExecuteReaderAsync()) { - return await reader.ToDictionaryAsync(keyFunc); + return await reader.ReadDictionaryAsync(keyFunc); } } /// Executes the and reads all the records in a lookup, grouped by key, using the supplied to generate the key - public static HashLookup ReadLookup(this IDbCommand cmd, Func keyFunc) + public static HashLookup ExecuteLookup(this IDbCommand cmd, Func keyFunc) { Contract.Requires(cmd != null); Contract.Requires(keyFunc != null); Contract.Ensures(Contract.Result>() != null); using (var reader = cmd.ExecuteReader()) { - return reader.ToLookup(keyFunc); + return reader.ReadLookup(keyFunc); } } /// Executes the and reads all the records in a lookup, grouped by key, using the supplied to generate the key - public static async Task> ReadLookupAsync(this SqlCommand cmd, Func keyFunc) + public static async Task> ExecuteLookupAsync(this SqlCommand cmd, Func keyFunc) { Contract.Requires(cmd != null); Contract.Requires(keyFunc != null); Contract.Ensures(Contract.Result>() != null); using (var reader = await cmd.ExecuteReaderAsync()) { - return await reader.ToLookupAsync(keyFunc); + return await reader.ReadLookupAsync(keyFunc); } } diff --git a/Mapper/ConnectionExtension.cs b/Mapper/ConnectionExtension.cs index bc3e943..b4b7689 100644 --- a/Mapper/ConnectionExtension.cs +++ b/Mapper/ConnectionExtension.cs @@ -46,7 +46,7 @@ public static T QuerySingle(this IDbConnection cnn, string sql, object parame using (var cmd = cnn.CreateCommand()) { SetupCommand(cmd, cnn, sql, parameters); - return cmd.ReadSingle(); + return cmd.ExecuteSingle(); } } @@ -59,7 +59,7 @@ public static Task QuerySingleAsync(this SqlConnection cnn, string sql, ob using (var cmd = cnn.CreateCommand()) { SetupCommand(cmd, cnn, sql, parameters); - return cmd.ReadSingleAsync(); + return cmd.ExecuteSingleAsync(); } } @@ -71,7 +71,7 @@ public static T QuerySingleOrDefault(this IDbConnection cnn, string sql, obje using (var cmd = cnn.CreateCommand()) { SetupCommand(cmd, cnn, sql, parameters); - return cmd.ReadSingleOrDefault(); + return cmd.ExecuteSingleOrDefault(); } } @@ -83,7 +83,7 @@ public static Task QuerySingleOrDefaultAsync(this SqlConnection cnn, strin using (var cmd = cnn.CreateCommand()) { SetupCommand(cmd, cnn, sql, parameters); - return cmd.ReadSingleOrDefaultAsync(); + return cmd.ExecuteSingleOrDefaultAsync(); } } @@ -97,7 +97,7 @@ public static List QueryList(this IDbConnection cnn, string sql, object pa using (var cmd = cnn.CreateCommand()) { SetupCommand(cmd, cnn, sql, parameters); - return cmd.ReadList(); + return cmd.ExecuteList(); } } @@ -111,7 +111,7 @@ public static Task> QueryListAsync(this SqlConnection cnn, string sql using (var cmd = cnn.CreateCommand()) { SetupCommand(cmd, cnn, sql, parameters); - return cmd.ReadListAsync(); + return cmd.ExecuteListAsync(); } } @@ -126,7 +126,7 @@ public static Dictionary QueryDictionary(this IDbCon using (var cmd = cnn.CreateCommand()) { SetupCommand(cmd, cnn, sql, null); - return cmd.ReadDictionary(keyFunc); + return cmd.ExecuteDictionary(keyFunc); } } @@ -141,7 +141,7 @@ public static Task> QueryDictionaryAsync( using (var cmd = cnn.CreateCommand()) { SetupCommand(cmd, cnn, sql, null); - return cmd.ReadDictionaryAsync(keyFunc); + return cmd.ExecuteDictionaryAsync(keyFunc); } } @@ -157,7 +157,7 @@ public static Dictionary QueryDictionary(this IDbCon using (var cmd = cnn.CreateCommand()) { SetupCommand(cmd, cnn, sql, parameters); - return cmd.ReadDictionary(keyFunc); + return cmd.ExecuteDictionary(keyFunc); } } @@ -173,7 +173,7 @@ public static Task> QueryDictionaryAsync( using (var cmd = cnn.CreateCommand()) { SetupCommand(cmd, cnn, sql, parameters); - return cmd.ReadDictionaryAsync(keyFunc); + return cmd.ExecuteDictionaryAsync(keyFunc); } } @@ -188,7 +188,7 @@ public static ILookup QueryLookup(this IDbConnection using (var cmd = cnn.CreateCommand()) { SetupCommand(cmd, cnn, sql, null); - return cmd.ReadLookup(keyFunc); + return cmd.ExecuteLookup(keyFunc); } } @@ -204,7 +204,7 @@ public static ILookup QueryLookup(this IDbConnection using (var cmd = cnn.CreateCommand()) { SetupCommand(cmd, cnn, sql, parameters); - return cmd.ReadLookup(keyFunc); + return cmd.ExecuteLookup(keyFunc); } } @@ -219,7 +219,7 @@ public static async Task> QueryLookupAsync> QueryLookupAsyncReads exactly one item from the reader /// when zero values read or more than one value can be read - public static T Single(this IDataReader reader) + public static T ReadSingle(this IDataReader reader) { Contract.Requires(reader != null); Contract.Requires(reader.IsClosed == false); @@ -30,7 +30,7 @@ public static T Single(this IDataReader reader) /// Reads exactly one item from the reader /// when zero values read or more than one value can be read - public static async Task SingleAsync(this SqlDataReader reader) + public static async Task ReadSingleAsync(this SqlDataReader reader) { Contract.Requires(reader != null); Contract.Requires(reader.IsClosed == false); @@ -44,7 +44,7 @@ public static async Task SingleAsync(this SqlDataReader reader) /// Reads zero or one items from the reader /// Returns the default vaue of T if no values be read, i.e may return null - public static T SingleOrDefault(this IDataReader reader) + public static T ReadSingleOrDefault(this IDataReader reader) { Contract.Requires(reader != null); Contract.Requires(reader.IsClosed == false); @@ -55,7 +55,7 @@ public static T SingleOrDefault(this IDataReader reader) /// Reads zero or one items from the reader /// Returns the default vaue of T if no values be read, i.e may return null - public static async Task SingleOrDefaultAsync(this SqlDataReader reader) + public static async Task ReadSingleOrDefaultAsync(this SqlDataReader reader) { Contract.Requires(reader != null); Contract.Requires(reader.IsClosed == false); @@ -65,7 +65,7 @@ public static async Task SingleOrDefaultAsync(this SqlDataReader reader) } /// Reads all the records in the reader into a list - public static List ToList(this IDataReader reader) + public static List ReadList(this IDataReader reader) { Contract.Requires(reader != null); Contract.Requires(reader.IsClosed == false); @@ -80,7 +80,7 @@ public static List ToList(this IDataReader reader) } /// Reads all the records in the reader into a list - public static async Task> ToListAsync(this SqlDataReader reader) + public static async Task> ReadListAsync(this SqlDataReader reader) { Contract.Requires(reader != null); Contract.Requires(reader.IsClosed == false); @@ -95,7 +95,7 @@ public static async Task> ToListAsync(this SqlDataReader reader) } /// Reads all the records in the reader into a dictionary, using the supplied to generate the key - public static Dictionary ToDictionary(this IDataReader reader, Func keyFunc) + public static Dictionary ReadDictionary(this IDataReader reader, Func keyFunc) { Contract.Requires(reader != null); Contract.Requires(keyFunc != null); @@ -113,7 +113,7 @@ public static Dictionary ToDictionary(this IDataRead } /// Reads all the records in the reader into a dictionary, using the supplied to generate the key - public static async Task> ToDictionaryAsync(this SqlDataReader reader, Func keyFunc) + public static async Task> ReadDictionaryAsync(this SqlDataReader reader, Func keyFunc) { Contract.Requires(reader != null); Contract.Requires(keyFunc != null); @@ -131,7 +131,7 @@ public static async Task> ToDictionaryAsyncReads all the records in the lookup, group by key, using the supplied to generate the key - public static HashLookup ToLookup(this IDataReader reader, Func keyFunc) + public static HashLookup ReadLookup(this IDataReader reader, Func keyFunc) { Contract.Requires(reader != null); Contract.Requires(keyFunc != null); @@ -148,7 +148,7 @@ public static HashLookup ToLookup(this IDataReader r } /// Reads all the records in the lookup, group by key, using the supplied to generate the key - public static async Task> ToLookupAsync(this SqlDataReader reader, Func keyFunc) + public static async Task> ReadLookupAsync(this SqlDataReader reader, Func keyFunc) { Contract.Requires(reader != null); Contract.Requires(keyFunc != null); @@ -164,7 +164,6 @@ public static async Task> ToLookupAsync(t return lookup; } - private static Func GetMappingFunc(IDataReader reader) { var columns = CreateColumnList(reader); diff --git a/Mapper/Mapper.nuspec b/Mapper/Mapper.nuspec index 1c08412..1be65a9 100644 --- a/Mapper/Mapper.nuspec +++ b/Mapper/Mapper.nuspec @@ -2,7 +2,7 @@ Mapper - 1.0.1.5 + 1.0.2.0 BusterWood A convention-based object cloner, object-object mapper (like AutoMapper), IDataReader to object mapper, object to IDbDataParameter mapper, etc. https://github.com/busterwood/mapper diff --git a/Mapper/Properties/AssemblyInfo.cs b/Mapper/Properties/AssemblyInfo.cs index ccaf7df..54b63f3 100644 --- a/Mapper/Properties/AssemblyInfo.cs +++ b/Mapper/Properties/AssemblyInfo.cs @@ -11,7 +11,7 @@ [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.1.5")] +[assembly: AssemblyVersion("1.0.2.0")] +[assembly: AssemblyFileVersion("1.0.2.0")] [assembly: InternalsVisibleTo("Mapper.UnitTests")] \ No newline at end of file diff --git a/README.md b/README.md index ae9f62c..c66d8d4 100644 --- a/README.md +++ b/README.md @@ -69,11 +69,11 @@ ILookup list = connection.QueryLookup("select * from dbo ### IDataReader methods `IDataReader` has the following extension methods: -* `Single()` for reading exactly one row -* `SingleOrDefault()` for reading zero or one rows -* `ToList()` for reading all records into a `List` -* `ToDictinary(Func keyFunc)` for reading all records into a `Dictinary` using the supplied function to get work out the key. Note that the key must be unique. -* `ToLookup(Func keyFunc)` for reading all records into a `ILookup` using the supplied function to get work out the key. Each key may have multiple values. +* `ReadSingle()` for reading exactly one row +* `ReadSingleOrDefault()` for reading zero or one rows +* `ReadList()` for reading all records into a `List` +* `ReadDictinary(Func keyFunc)` for reading all records into a `Dictinary` using the supplied function to get work out the key. Note that the key must be unique. +* `ReadLookup(Func keyFunc)` for reading all records into a `ILookup` using the supplied function to get work out the key. Each key may have multiple values. ### SqlDataReader async methods @@ -85,11 +85,11 @@ Additionally `SqlDataReader` has the same set of methods as `IDataReader` but wi For convenience `Mapper` adds the following extension method to `IDbCommand`: -* `ReadSingle()` for exeucting the command and reading exactly one row -* `ReadSingleOrDefault()` for exeucting the command and reading zero or one rows -* `ReadList()` for exeucting the command and reading all records into a `List` -* `ReadDictinary(Func keyFunc)` for exeucting the command and reading all records into a `Dictinary` using the supplied function to get work out the key. Note that the key must be unique. -* `ReadLookup(Func keyFunc)` for exeucting the command and reading all records into a `ILookup` using the supplied function to get work out the key. Each key may have multiple values. +* `ExecuteSingle()` for exeucting the command and reading exactly one row +* `ExecuteSingleOrDefault()` for exeucting the command and reading zero or one rows +* `ExecuteList()` for exeucting the command and reading all records into a `List` +* `ExecuteDictinary(Func keyFunc)` for exeucting the command and reading all records into a `Dictinary` using the supplied function to get work out the key. Note that the key must be unique. +* `ExecuteLookup(Func keyFunc)` for exeucting the command and reading all records into a `ILookup` using the supplied function to get work out the key. Each key may have multiple values. ### SqlCommand async methods