-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
33 lines (22 loc) · 1.07 KB
/
Program.cs
File metadata and controls
33 lines (22 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using Microsoft.AspNetCore.OData;
using Microsoft.OData.ModelBuilder;
using ODataGroupByNestedDynamicProperty.Models;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
ODataModelBuilder modelBuilder = new();
EntityTypeConfiguration<Customer> customerType = modelBuilder.EntityType<Customer>();
customerType.HasKey(c => c.Id);
customerType.ComplexProperty(c => c.Address);
Type addressType = typeof(Address);
ComplexTypeConfiguration addressConfiguration = modelBuilder.AddComplexType(addressType);
addressConfiguration.AddProperty(addressType.GetProperty(nameof(Address.City)));
addressConfiguration.AddDynamicPropertyDictionary(addressType.GetProperty(nameof(Address.DynamicProperties)));
modelBuilder.EntitySet<Customer>("Customers");
builder.Services.AddControllers().AddOData(
options => options.Select().Filter().OrderBy().Expand().Count().SetMaxTop(null).AddRouteComponents(
string.Empty,
modelBuilder.GetEdmModel()));
WebApplication app = builder.Build();
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();