-
Notifications
You must be signed in to change notification settings - Fork 711
/
Copy pathPersonModelConfiguration.cs
48 lines (40 loc) · 1.28 KB
/
PersonModelConfiguration.cs
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
namespace ApiVersioning.Examples.Configuration;
using ApiVersioning.Examples.Models;
using Asp.Versioning;
using Asp.Versioning.OData;
using Microsoft.OData.ModelBuilder;
public class PersonModelConfiguration : IModelConfiguration
{
private static void ConfigureV1( ODataModelBuilder builder )
{
var person = ConfigureCurrent( builder );
person.Ignore( p => p.Email );
person.Ignore( p => p.Phone );
}
private static void ConfigureV2( ODataModelBuilder builder ) => ConfigureCurrent( builder ).Ignore( p => p.Phone );
private static EntityTypeConfiguration<Person> ConfigureCurrent( ODataModelBuilder builder )
{
var person = builder.EntitySet<Person>( "People" ).EntityType;
person.HasKey( p => p.Id );
return person;
}
public void Apply( ODataModelBuilder builder, ApiVersion apiVersion, string routePrefix )
{
if ( routePrefix != "api" )
{
return;
}
switch ( apiVersion.MajorVersion )
{
case 1:
ConfigureV1( builder );
break;
case 2:
ConfigureV2( builder );
break;
default:
ConfigureCurrent( builder );
break;
}
}
}