private static void AutoMappingWithConfigurationDTO(QueryContext context) { MapperConfig.Init(); // custom configuration Product product = context.Products.Find(2); ProductDTO productDTO = Mapper.Map <ProductDTO>(product); Console.WriteLine($"{productDTO.Name} - Cost {productDTO.Cost} - Qty {productDTO.StockQuantity}"); }
private static void MappingProperties(QueryContext context) { MapperConfig.Init(); Order order = context.Orders.Find(1); OrderDTO orderDTO = Mapper.Map <OrderDTO>(order); Console.WriteLine($"Client {orderDTO.ClientName} - Order Total {orderDTO.OrderTotal}"); }
private static void AutoMappingCollection(QueryContext context) { MapperConfig.Init(); // custom configuration // v.1 //Product[] products = context.Products.ToArray(); //List<ProductDTO> productDTOs = Mapper.Map<Product[], List<ProductDTO>>(products); // v.2 List <ProductDTO> productDTOs = context.Products .ProjectTo <ProductDTO>() .ToList(); foreach (var productDTO in productDTOs) { Console.WriteLine($"{productDTO.Name} - Cost {productDTO.Cost} - Qty {productDTO.StockQuantity}"); } }
static void Main(string[] args) { // Add Reference to System.Web.Extensions (JSSerializer) // Install Newtonsoft.Json MapperConfig.Init(); // JavaScriptSerializer SerializeDeserialize(); Serializing(); Deserializing(); UsingSerializerWithDictionaries(); UsingSerializerWithDTOs(); // JSON.Net UsingJsonNet(); UsingJsonNetWithAnonymousTypes(); UsingJsonNetWithAttributes(); UsingJsonNetWithLINQToJson(); UsingJsonNetAttributesToPreventCircularRef(); }