Parameter to generate metadata document
darinvanatta opened this issue · 10 comments
Hi,
Using odata2poco as a class library has been been seamless and has saved me so much time.
I now have a need to generate the metadata document xml file each time my app starts so I can parse out more info that is not part of the POCO class file.
Would be possible to add a parameter that if passed would write the metadata document file instead of the POCO class file?
Thanks!
Can I know what the info you need?
It may be available in the API, so you can use it.
Thanks for your help!
Right now I just want to get entity names, entity elements and data types like you are doing for POCO class.
Here I'm getting the entity name but I can get the element names and their data types though I see in the debugger where they are in the image below. The debugger image shows the path to the element data types starting with "entity.Type.ElementType" but Intellisense shows "ElementType" is not an option though I see it in the debugger image.
You can get the metadata as given below:
var o2p = new O2P(setting);
var code = await o2p.GenerateAsync(connString);
//generate metadata as xml file
string metaData = o2p.MetaDataAsString;
These aren't errors, but log messages because the EntityName/ propertyName is a reserved c# keyword or the name of the property is the same name as its class type which causes the compiler error CS0542
e.g.,the message:
Rename the property 'Applicant.Applicant' to 'applicant' for avoiding the Compiler error CS0542
The message means that the property 'Applicant' in the class 'Applicant' is renamed to 'applicant' (lowercase) to avoid the compilation error CS0542
O2pgen rename the entity/property and show these messages during the generation, so you can avoid the compilation errors you get in your issue #12.
These information are very important when you retrieve data from Odata feeds using the generated POCO with Odata client tools and it's better to save these log messages.
In the next release, I can control show/hide these messages by an option or saving to log file.
Hi @darinvanatta
You can download a new version 3.2.0 from github
- The warning are hided with the option
--show-warning
to show. - All renamed properties have an attribute
JsonProperty
, because Odata is case sensitive for the name of the properties/classes otherwise you get null values for these properties, example:
[JsonProperty("Applicant")]
public virtual string applicant {get;set;}
Try to reterive Applicant
Entity and be sure that applicant
property is not null.
I appreciate your feedback
Thanks @darinvanatta for feedback.
I suggest you generate a separate class library for the POCO classes and reference it in your project.
You can benefit from Linq and reflection and utilize the code as your needs.
Reflection on a class library works exactly as I need... Thanks!
A new version 3.2.0.7 including fix to this issue can be downloaded from github