static void Main(string[] args) { var connStr = ConfigurationManager.ConnectionStrings["CustomMapperConnStr"]; using (var conn = new SqlConnection(connStr.ConnectionString)) { conn.Open(); var unit1 = new Unit { Name = "USD" }; new UnitMapper(conn).Save(unit1); var unit2 = new Unit { Name = "РУБ", Description = "рубли" }; new UnitMapper(conn).Save(unit2); var allUnits = new UnitMapper(conn).GetAll(); var unit = new UnitMapper(conn).Get(unit1.Id); unit.Description = "$"; new UnitMapper(conn).Save(unit); new UnitMapper(conn).Delete(new Unit {Id = unit2.Id}); var indicator1 = new Indicator {Title = "Ind1"}; new IndicatorMapper(conn).Save(indicator1); var indicator2 = new Indicator { Title = "Ind2", UnitId = unit1.Id}; new IndicatorMapper(conn).Save(indicator2); try { var indicator3 = new Indicator { Title = "Ind3", UnitId = 1000 }; new IndicatorMapper(conn).Save(indicator3); } catch (Exception) { // } var allIndicators = new IndicatorMapper(conn).GetAll(); var i1 = new IndicatorMapper(conn).Get(indicator1.Id); try { new UnitMapper(conn).Delete(unit1); } catch (Exception) { } new IndicatorMapper(conn).Delete(indicator2); new UnitMapper(conn).Delete(unit1); conn.Close(); } }
static void Main(string[] args) { var connStr = ConfigurationManager.ConnectionStrings["CustomMapperConnStr"]; using (var conn = new SqlConnection(connStr.ConnectionString)) { conn.Open(); var unit1 = new Unit { Name = "USD" }; new UnitMapper(conn).Save(unit1); var unit2 = new Unit { Name = "РУБ", Description = "рубли" }; new UnitMapper(conn).Save(unit2); var allUnits = new UnitMapper(conn).GetAll(); var unit1_1 = new UnitMapper(conn).Get(unit1.Id); var unit1_2 = new UnitMapper(conn).Get(unit1.Id); unit1_1.Description = "$"; new UnitMapper(conn).Save(unit1_1); try { unit1_2.Description = "$"; new UnitMapper(conn).Save(unit1_2); } catch (Exception ex) { // } new UnitMapper(conn).Delete(unit1_1); try { new UnitMapper(conn).Delete(new Unit {Id = unit1_2.Id, TimeStamp = unit1_2.TimeStamp}); } catch (Exception ex) { // } conn.Close(); } }