public ShipMethodDto GetSimple(int id) { ShipMethod shipMethodEf = this.dbContext.ShipMethods.Find(id); if (shipMethodEf == null) { throw new ArgumentException("Not found id"); } ShipMethodDto shipMethodDto = new ShipMethodDto(); shipMethodDto.ModifiedDate = shipMethodEf.ModifiedDate; shipMethodDto.Name = shipMethodEf.Name; shipMethodDto.rowguid = shipMethodEf.rowguid; shipMethodDto.ShipBase = shipMethodEf.ShipBase; shipMethodDto.ShipMethodID = shipMethodEf.ShipMethodID; shipMethodDto.ShipRate = shipMethodEf.ShipRate; return shipMethodDto; }
private void TestGetSimple(IAdapter adapter, int count) { adapter.Prepare(); Stopwatch stp = new Stopwatch(); stp.Start(); for (int i = 0; i < count; i++) { ShipMethodDto dto5 = adapter.GetSimple(5); ShipMethodDto dto3 = adapter.GetSimple(3); ShipMethodDto dto1 = adapter.GetSimple(1); ShipMethodDto dto2 = adapter.GetSimple(2); ShipMethodDto dto4 = adapter.GetSimple(4); } stp.Stop(); Console.WriteLine("{0,-30} - {1,6} ms {2,6} us", adapter.Name, stp.ElapsedMilliseconds, Math.Round(1000.0 * stp.Elapsed.TotalMilliseconds / (5 * count), 4)); adapter.Relase(); }
private void MapperConfigure(MapperInstance cfd) { cfd.AddMap<Person, PersonInfoDto>(src => { PersonInfoDto dst = new PersonInfoDto(); dst.InjectFrom(src); dst.EmployeeBrithDate = src.Employee?.BirthDate; return dst; }); cfd.AddMap<EmailAddress, EmailDto>(src => { EmailDto dst = new EmailDto(); dst.InjectFrom(src); dst.EmailAddress = src.EmailAddress1; return dst; }); cfd.AddMap<ShipMethod, ShipMethodDto>(src => { ShipMethodDto dst = new ShipMethodDto(); dst.InjectFrom(src); return dst; }); cfd.AddMap<ProductListPriceHistory, ProductListPriceHistoryDto>(src => { ProductListPriceHistoryDto dst = new ProductListPriceHistoryDto(); dst.InjectFrom(src); return dst; }); cfd.AddMap<Product, ProductDto>(src => { ProductDto dst = new ProductDto(); dst.InjectFrom(src); dst.ProductListPriceHistories = new List<ProductListPriceHistoryDto>(); foreach (ProductListPriceHistory item in src.ProductListPriceHistories) { ProductListPriceHistoryDto itemDto = new ProductListPriceHistoryDto(); itemDto.InjectFrom(item); dst.ProductListPriceHistories.Add(itemDto); } return dst; }); cfd.AddMap<ProductModel, ProductModelDto>(src => { ProductModelDto dst = new ProductModelDto(); dst.InjectFrom(src); return dst; }); cfd.AddMap<Product, Product2Dto>(src => { Product2Dto dst = new Product2Dto(); dst.InjectFrom(src); dst.ProductModel = new ProductModelDto(); dst.ProductModel.InjectFrom(src.ProductModel); dst.ProductModelID = src.ProductModel?.ProductModelID; return dst; }); }
public ShipMethodDto GetSimple(int id) { string sql = @"SELECT TOP 1 [ShipMethodID] ,[Name] ,[ShipBase] ,[ShipRate] ,[rowguid] ,[ModifiedDate] FROM [AdventureWorks2014].[Purchasing].[ShipMethod] WHERE [ShipMethodID] = @id"; using (SqlConnection connection = new SqlConnection(this.connectionString)) { SqlCommand cmd = connection.CreateCommand(); cmd.CommandText = sql; cmd.CommandType = System.Data.CommandType.Text; cmd.Parameters.AddWithValue("@id", id); if (connection.State != System.Data.ConnectionState.Open) { connection.Open(); } using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { ShipMethodDto personInfo = new ShipMethodDto(); personInfo.ShipMethodID = Convert.ToInt32(reader["ShipMethodID"]); personInfo.ModifiedDate = this.MapToDateTime2(reader, "ModifiedDate"); personInfo.Name = this.MapToString(reader, "Name"); personInfo.ShipBase = Convert.ToDecimal(reader["ShipBase"]); personInfo.ShipRate = Convert.ToDecimal(reader["ShipRate"]); personInfo.rowguid = (Guid)reader["rowguid"]; return personInfo; } } } throw new ArgumentException("Not found id"); }