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 Guid CustomerId { get; private set; } | |
| public string OrderNo { get; private set; } | |
| public DateTime DatePlaced { get; private set; } | |
| public DateTime? DatePaid { get; private set; } | |
| public decimal OrderTotal { get; private set; } | |
| public decimal TotalVat { get; private set; } | |
| public int? ShippingType { get; private 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
| using (var ctx = new OrderContext()) | |
| { | |
| //Loading Order only | |
| Order o = await ctx.Orders.GetAsync(OrderId); | |
| //Loads Order LineItems using Lazy Loading | |
| var orderItems = o.LineItems; | |
| } |
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 OrderingDbContext : DbContext | |
| { | |
| public DbSet<Order> Order { get; set; } | |
| public DbSet<LineItem> LineItem { get; set; } | |
| public OrderingDbContext(DbContextOptions<OrderingDbContext> options) : base(options) | |
| { | |
| } | |
| protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) |
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 context = new OrderingDbContext()) | |
| { | |
| // Load all Orders and related Line Items | |
| var orders = context.Order | |
| .Include(b => b.LineItem) | |
| .ToList(); | |
| // Load an Order and it's related Line Items | |
| var orders = context.Order | |
| .Where(x => x.OrderId == orderId) |
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
| services.AddApiVersioning(options => | |
| { | |
| options.ReportApiVersions = true; | |
| options.DefaultApiVersion = new ApiVersion(1, 0); | |
| options.AssumeDefaultVersionWhenUnspecified = true; | |
| }); |
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
| namespace HomeController | |
| { | |
| [ApiVersion("1.0")] | |
| [Route("api/Values")] | |
| public class HomeController : Controller | |
| { | |
| [HttpGet] | |
| public IEnumerable<string> Get() | |
| { | |
| return new string[] { "Value1 from Version 1", "value2 from Version 1" }; |
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
| [Route("api/{v:apiVersion}/Values")] | |
| public class HomeController : Controller | |
| { | |
| [HttpGet] | |
| public IEnumerable<string> Get() | |
| { | |
| return new string[] { "Value1 from Version 2", "value2 from Version 2" }; | |
| } | |
| } |
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
| services.AddApiVersioning(options => | |
| { | |
| options.ReportApiVersions = true; | |
| options.DefaultApiVersion = new ApiVersion(1, 0); | |
| options.AssumeDefaultVersionWhenUnspecified = true; | |
| //Add Conventions | |
| options.Conventions.Controller<HomeController>().HasApiVersion(new ApiVersion(1, 0)); | |
| options.Conventions.Controller<HomeV2Controller>().HasApiVersion(new ApiVersion(2, 0)); | |
| }); |
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
| [ApiVersionNeutral] | |
| [RoutePrefix( "api/[controller]" )] | |
| public class PingController : Controller { | |
| return Ok(); | |
| } |
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
| namespace HomeController | |
| { | |
| [ApiVersion("1.0")] | |
| [Route("api/Values")] | |
| public class HomeController : Controller | |
| { | |
| [HttpGet] | |
| public IEnumerable<string> Get() | |
| { | |
| return new string[] { "Value1 from Version 1", "value2 from Version 1" }; |