Skip to content

Instantly share code, notes, and snippets.

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);
}
public class Order
{
public int Id { get; set; }
public int CustomerId { get; set; }
public DateTime OrderDate { get; set; }
public Customer Customer { get; set; }
}
GetColumns(typeof(Order))
.ToList()
.ForEach(prop => Console.WriteLine(prop));
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))
{
var columns = GetColumns(typeof(Order));
var queryGenerator = new SqlServerQueryGeneration();
var insertQuery = queryGenerator.GetInsertQuery(columns, "Order");
var selectQuery = queryGenerator.GetSelectQuery(columns, "Order");
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; }
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)
{
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>();
}
Console.WriteLine(string.Format("Mi nombre es {0} y tengo {1} años", name, age));
Console.WriteLine(string.Format("Mi nombre es {0} naci en {1:y} y tengo {2} años", name,date, age));