This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| internal static IEnumerable<string> ReadLines(this string s) | |
| { | |
| string line; | |
| using (var sr = new StringReader(s)) | |
| while ((line = sr.ReadLine()) != null) | |
| yield return line; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ClutchProvider : WrappedInsightDbProvider | |
| { | |
| private ClutchProvider() | |
| { | |
| } | |
| public override IEnumerable<Type> SupportedTypes | |
| { | |
| get |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // somewhere early in App.xaml.cs | |
| AppDomain.CurrentDomain.UnhandledException += (s, e) => | |
| LogUnhandledException((Exception) e.ExceptionObject, "AppDomain.CurrentDomain.UnhandledException"); | |
| DispatcherUnhandledException += (s, e) => | |
| LogUnhandledException(e.Exception, "Application.Current.DispatcherUnhandledException"); | |
| TaskScheduler.UnobservedTaskException += (s, e) => | |
| LogUnhandledException(e.Exception, "TaskScheduler.UnobservedTaskException"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ReSharper disable InconsistentNaming | |
| using FluentValidation; | |
| using NUnit.Framework; | |
| using FluentValidation.TestHelper; | |
| namespace FailingTest | |
| { | |
| public class Hello | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static void OtherInsertOverloadExample(BulkInserter<Person> bulkInserter, IEnumerable<Person> people) | |
| { | |
| // sql connection is being managed externally | |
| foreach (var person in people) | |
| { | |
| // contrived example... do some work on each person | |
| person.Salary = DetermineSalary(person); | |
| // this will add the object to a list managed by BulkInserter<T> | |
| // the data will not be written to the database until the list count == batch size |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static Func<T, object> CreatePropertyGetter(PropertyInfo propertyInfo) | |
| { | |
| if (typeof(T) != propertyInfo.DeclaringType) | |
| throw new ArgumentException(); | |
| var instance = Expression.Parameter(propertyInfo.DeclaringType, "i"); | |
| var property = Expression.Property(instance, propertyInfo); | |
| var convert = Expression.TypeAs(property, typeof(object)); | |
| return (Func<T, object>)Expression.Lambda(convert, instance).Compile(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var bi = new BulkInserter<Person>(sqlConnection, "People"); | |
| bi.PreBulkInsert += (sender, args) => | |
| { | |
| // args.DataTable - this is the actual datatable being written to the server | |
| // you can modify the rows that will be written | |
| // args.Items - this is an array of the objects used to create the datatable | |
| // that will be written. modifying these objects at this point has no effect | |
| // on the bulk insert operation, but it's nice to have them if you need them | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static void BulkInserterExample(string connectionString, IEnumerable<Person> people) | |
| { | |
| using (var sqlConnection = new SqlConnection(connectionString)) | |
| { | |
| var bi = new BulkInserter<Person>(sqlConnection, "People", batchSize: 2000); | |
| sqlConnection.Open(); | |
| bi.Insert(people); | |
| sqlConnection.Close(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static void SqlBulkCopyExample(string connectionString, IEnumerable<Person> people) | |
| { | |
| using (var dataTable = new DataTable()) | |
| { | |
| dataTable.Columns.Add("Id"); | |
| dataTable.Columns.Add("Name"); | |
| dataTable.Columns.Add("SpouseName"); | |
| dataTable.Columns.Add("BirthDate"); | |
| dataTable.Columns.Add("Salary"); | |
| dataTable.Columns.Add("IsMarried"); |