Outdated EDM library and use of System.Text.Json?
LarsBauer opened this issue · 4 comments
Hi,
First oft all, thanks for this great library. I was really missing such a simple to use tool for generation of model classes.
Unfortunately I receive some minor errors in the generated code when running odata2poco as a local dotnet tool (see command below).
dotnet tool run dotnet-o2pgen `
--url "$organizationUrl/api/data/v9.1/" `
--auth oauth2 `
--user $clientId `
--password $clientSecret `
--token-endpoint "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" `
--token-params "scope=$organizationUrl/.default" `
--navigation `
--nullable `
--include *
The type or namespace name 'Library' does not exist in the namespace 'Microsoft.OData.Edm'
public virtual Microsoft.OData.Edm.Library.Date birthdate {get;set;}
~~~~~~~
Microsoft removed the Library
namespace starting with v7 of the EDM library. The correct namespace is Microsoft.OData.Edm.Date
. I could remove this part manually but upon re-generation of the model the changes get overriden, which is kind of suboptimal. So is it possible for you to update this dependency or is there any configuration I am missing?
The type or namespace name 'JsonProperty' could not be found.`
[JsonProperty("event")]
~~~~~~~~~~~~
public virtual string Event {get;set;}
JsonProperty
is part of Newtonsoft.Json namespace. Microsoft removed this namespace from dotnet core 3 and introduced an own namespace for JSON de-/serialization. As mentioned before I could easily fix this problem by replacing JsonProperty
with JsonPropertyName
and adding a using for System.Text.Json.Serialization
but I have to do it everytime the schema changes. So it would be awesome if you switch to System.Text.Json
or provide a commandline option which package to use.
Thanks in advance!
Thanks for using OData2Poco library.
OData2poco already use v7 of the EDM library,
I'll investigate your concerns and publish a new version which:
- correct namespace
- Support System.Text.Json.Serialization in net core 3
I'll check the generated model for running in net core3.
I opened a PR to address the namespace issue. Can you please have a look and release a updated version of the package if there are no issues with my changes? Thank you!
I puplished the package v3.4.0
Now, Supporting System.Text.Json
is implemented and it is available in v3.4.1 by providing attribute named json3
(json
for json.net)
Example:
dotnet o2pgen -a json3 --nullable --case camel --filename poco.cs --url http://services.odata.org/V4/OData/OData.svc
output sample : poco.zip
using System.Text.Json.Serialization;
public partial class ProductDetail
{
[JsonPropertyName("ProductID")]
public int productID {get;set;} //PrimaryKey not null
[JsonPropertyName("Details")]
public string details {get;set;}
}