|
2 | 2 | using Microsoft.AspNetCore.OData; |
3 | 3 | using Microsoft.OData.ModelBuilder; |
4 | 4 | var builder = WebApplication.CreateBuilder(args); |
5 | | -//var modelBuilder = new ODataConventionModelBuilder(); |
6 | | -//modelBuilder.EntitySet<OrdersDetails>("Orders"); |
| 5 | +var modelBuilder = new ODataConventionModelBuilder(); |
| 6 | +modelBuilder.EntitySet<OrdersDetails>("Orders"); |
7 | 7 | // Add services to the container. |
8 | 8 | builder.Services.AddRazorPages(); |
9 | 9 | builder.Services.AddControllers(); |
10 | | -//builder.Services.AddControllers().AddOData( |
11 | | -// options => options |
12 | | -// .Count() |
13 | | -// .Filter() |
14 | | -// .OrderBy() |
15 | | -// .Expand() |
16 | | -// .SetMaxTop(null) |
17 | | -// .AddRouteComponents("odata", modelBuilder.GetEdmModel())); |
18 | | -//builder.Services.AddCors(options => |
19 | | -//{ |
20 | | -// options.AddPolicy("AllowAllHeaders", |
21 | | -// builder => builder |
22 | | -// .WithOrigins("https://localhost:7123") // Allow frontend URL |
23 | | -// .AllowAnyMethod() |
24 | | -// .AllowAnyHeader() |
25 | | -// .SetIsOriginAllowed(origin => true) // Allow all origins if needed |
26 | | -// .AllowCredentials()); // If using authentication |
27 | | -//}); |
| 10 | +builder.Services.AddControllers().AddOData( |
| 11 | + options => options |
| 12 | + .Count() |
| 13 | + .Filter() |
| 14 | + .OrderBy() |
| 15 | + .Expand() |
| 16 | + .SetMaxTop(null) |
| 17 | + .AddRouteComponents("odata", modelBuilder.GetEdmModel())); |
| 18 | +builder.Services.AddCors(options => |
| 19 | +{ |
| 20 | + options.AddPolicy("AllowAllHeaders", |
| 21 | + builder => builder |
| 22 | + .WithOrigins("https://localhost:7123") // Allow frontend URL |
| 23 | + .AllowAnyMethod() |
| 24 | + .AllowAnyHeader() |
| 25 | + .SetIsOriginAllowed(origin => true) // Allow all origins if needed |
| 26 | + .AllowCredentials()); // If using authentication |
| 27 | +}); |
28 | 28 | var app = builder.Build(); |
29 | 29 |
|
30 | 30 | // Configure the HTTP request pipeline. |
|
0 commit comments