OData / odata.net

ODataLib: Open Data Protocol - .NET Libraries and Frameworks
https://docs.microsoft.com/odata
Other
683 stars 349 forks source link

Provide a better annotation API and implementation. #1229

Open NetTecture opened 6 years ago

NetTecture commented 6 years ago

The current annotation api is an afterhought and ridiculous bad to work with. There is no way to add annotations to anything while you define them and the characteristics i ncode, you first MUST pull the model out and then write something like that:

ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); var model = builder.GetEdmModel() as EdmModel; model.SetVocabularyAnnotation( new EdmAnnotation(model.EntityContainer.FindEntitySet("People").EntityType().FindProperty("FullName"), new EdmTerm("Org.OData.Core.V1", "Computed", EdmPrimitiveTypeKind.Boolean), new EdmBooleanConstant(true)));

This is bad, particuarlly because it also affects elements such as. Description, Language Dependency, Permissions.

This makes it impossible to have full onfiguration code in one place.

It should be possible to define at least the standard vocabulary items wit hthe model builder and not to add them to the model in a second step.

biaol-odata commented 6 years ago

@NetTecture Thanks for your feedback and enthusiasm for OData. We will look into this to see whether it can be improved. But still, after getting the model, all the annotation can be set in one place, e.g., by invoking model.SetVocabularyAnnotation() multiple times as needed. Am I missing anything?

Additionally, the APIs above are public APIs. If this area does require improvement, we either add a different approach as another feature, or revamp it completely in coming major release such as ODL v8.0. So it might take some time.

NetTecture commented 6 years ago

@biaol-odata Yes, you do.

Generally it means that I need a MODEL first, which is different from the modelbuilder. Which means I can not set the annotations where I define other thigns for an entity -I have to make asecond pass through all entities in order to define the annotations. Invonveneit as hell for those of us, i.e., not relying on attributes (because hey, no attribute independent assembly and I do not pull all of dotnet core webapi just because of attributes but define all information in ocde. Now I need two runs. One to set up the edm model in the builder, then a second pass just to set the annotations. On top, setting the annotations is VERY inconvenient - unless I define my own helper functions. Basically noone thinks that "ReadOnly" is a decent attribute on a builder - no, I have to rely on an API where I actually use strings.

biaol-odata commented 6 years ago

@NetTecture Thank you for the clarification. I thought that doing it in two passes (one for model and another one for annotations) might not be too bad. Additionally, while understanding that current design of setting up the Edm model and annotations are both of similar verbose style, but, IMHO, it is pretty straight forward and meets functional needs. We will take you comments into account in future feature planning.

NetTecture commented 6 years ago

@biaol-odata Let me give you an example how bad it is ;) I do not particularloy like the builder API - requires too many variables. So I work on a lot of functions (that i may submit here) that basically form a fluid API.

I am NOT able to say "WithProperties (c =>

then WithProperty ("name").IsReadOnly

SImply not possible. Second pass means I can NOT have a sinple point of truth. At least for standard vocabulary it is too verbose and I really get problems with the 2nd pass.

flieks commented 6 years ago

I also have problems with this on how to use the Display annotation (vocabulary) formatted value. Can't find any examples..