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 IEnumerable<string> GetColumns(Type type) | |
| { | |
| return type.GetProperties().Where(prop => !prop.PropertyType.IsGenericType && | |
| (prop.PropertyType.IsPrimitive || prop.PropertyType.Namespace.StartsWith("System")) | |
| ) | |
| .Select(prop => prop.Name); | |
| } |
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 Order | |
| { | |
| public int Id { get; set; } | |
| public int CustomerId { get; set; } | |
| public DateTime OrderDate { get; set; } | |
| public Customer Customer { get; set; } | |
| } |
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
| GetColumns(typeof(Order)) | |
| .ToList() | |
| .ForEach(prop => Console.WriteLine(prop)); |
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 SqlServerQueryGeneration : ISqlQueryGeneration | |
| { | |
| public string GetInsertQuery(IEnumerable<string> columns, string table, bool returnId = false) | |
| { | |
| if (!columns.Any()) | |
| { | |
| throw new ArgumentNullException("Columns are required"); | |
| } | |
| if (string.IsNullOrWhiteSpace(table)) | |
| { |
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 columns = GetColumns(typeof(Order)); | |
| var queryGenerator = new SqlServerQueryGeneration(); | |
| var insertQuery = queryGenerator.GetInsertQuery(columns, "Order"); | |
| var selectQuery = queryGenerator.GetSelectQuery(columns, "Order"); |
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 ReferentialConstraintAssociation | |
| { | |
| public ReferentialConstraintAssociation() | |
| { | |
| ForeignKeyNames = new List<string>(); | |
| MatchingReferenceDictionary = new Dictionary<object, object>(); | |
| } | |
| public List<string> ForeignKeyNames { get; set; } | |
| public Dictionary<object, object> MatchingReferenceDictionary { get; set; } |
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 SqlCopy : IDisposable | |
| { | |
| private DbConnection originConnection; | |
| private DbConnection destinationConnection; | |
| private ISqlQueryGeneration queryGenerator; | |
| private List<ReferentialConstraintAssociation> constraintAssociation; | |
| public SqlCopy(ISqlQueryGeneration generator, DbConnection origin, DbConnection destination) | |
| { | |
| if (origin == null) | |
| { |
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
| using (var copier = new SqlCopy.SqlCopy(new SqlServerQueryGeneration(), new SqlConnection("Data source=.; Initial Catalog=CopyDbSample;User Id=sa;Password=password"), new SqlConnection("Data source=.; Initial Catalog=CopyDbSample;User Id=sa;Password=password"))) | |
| { | |
| copier.CopyData<Customer>(); | |
| copier.CopyData<Product>(); | |
| copier.CopyData<Order>(); | |
| copier.CopyData<OrderDetail>(); | |
| } |
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
| Console.WriteLine(string.Format("Mi nombre es {0} y tengo {1} años", name, age)); |
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
| Console.WriteLine(string.Format("Mi nombre es {0} naci en {1:y} y tengo {2} años", name,date, age)); |
OlderNewer