1

I can't figure out what this code does.

public override string SelectController(ODataPath odataPath, HttpRequestMessage request)
{
    return odataPath != null &&
           odataPath.PathTemplate.StartsWith("~/entityset", 
                                  StringComparison.OrdinalIgnoreCase) ? "A" : null;
}

I know the syntactic meaning, but what does StartsWith("~/entityset" do ?

The problem is ~/entityset. I have no reference of what this entity set is and where is it taken from. I guess it could represent some entity set , which one ?

Is it some default OData mechanish to check URLs?

rene
  • 41,474
  • 78
  • 114
  • 152
Novak007
  • 426
  • 1
  • 9
  • 23

1 Answers1

1

This is used to decide on the routing within OData. Here some example URLs and what their path templates would be that all start with ~/entityset

http://localhost/odata/Students

"~/entityset"

http://localhost/odata/Students(1)

"~/entityset/key"

http://localhost/odata/Students(1)/Teachers

"~/entityset/key/navigation"

To find out which entity set it is you can look at the segments making up the path

((EntitySetPathSegment)request.ODataProperties().Segments.First()).EntitySetName

Segments.First() won't necessarily be a EntitySetPathSegment unless the path starts with ~/entityset so make sure you make that check first.

TomDoesCode
  • 3,580
  • 2
  • 18
  • 34