odata2poco - OData2Poco.dotnet.o2pgen 5.1.0-dev-36

o2gen is a CommandLine tool for generating c# and typescript POCO (DTO) classes,interfaces and records from OData feeds with lot of configuration parameters.

PM> Install-Package OData2Poco.dotnet.o2pgen -Version 5.1.0-dev-36 -Source https://www.myget.org/F/odata2poco/api/v3/index.json

Copy to clipboard

> nuget.exe install OData2Poco.dotnet.o2pgen -Version 5.1.0-dev-36 -Source https://www.myget.org/F/odata2poco/api/v3/index.json

Copy to clipboard

> dotnet tool install -g OData2Poco.dotnet.o2pgen --version 5.1.0-dev-36 --add-source https://www.myget.org/F/odata2poco/api/v3/index.json

Copy to clipboard
<DotNetCliToolReference Include="OData2Poco.dotnet.o2pgen" Version="5.1.0-dev-36" />
Copy to clipboard
source https://www.myget.org/F/odata2poco/api/v3/index.json

nuget OData2Poco.dotnet.o2pgen  ~> 5.1.0-dev-36
Copy to clipboard

> choco install OData2Poco.dotnet.o2pgen --version 5.1.0-dev-36 --source https://www.myget.org/F/odata2poco/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "odata2poco" -SourceLocation "https://www.myget.org/F/odata2poco/api/v2"
Install-Module -Name "OData2Poco.dotnet.o2pgen" -RequiredVersion "5.1.0-dev-36" -Repository "odata2poco" -AllowPreRelease
Copy to clipboard

Welcome to OData2Poco

OData2Poco is a code generation tool for generating plain-old CLR objects (POCO/DTO) in c# and typescript from OData feeds. POCO classes can be used in a typed RESTful client OData services. Code generation can be controlled by setting many options.


NuGet Version

NuGet Version

Global Tool NuGet Version

Chocolatey

Continuous integration

Build server Platform Build status
AppVeyor Windows Build status
Travis Linux / OS X Build Status

Announcing new Release: V5.0.0

  • New feature: generating typescript code as a single file or multi files(modules).
  • New feature: Generating class with init-only property, the new feature in c# 9.
  • New feature: Generating record type, the new feature in c# 9.
  • Fix issue #29 and consider class dependency when filtering model.
  • Moving o2pgen cli console tool from net45 to net472, #44
  • Calculate checksum256 for all packages and saved to file hosted in github releases.
  • Auto puplishing the chocolatey package.

How to use the new features: read wiki


Development packages

The developed packages can be downloaded from myget.org


Give a Star! :star:

If you are using this project, please show your support by giving this project a star!. Thanks!


Features of OData2Poco

  • Generate POCO classes corresponding to the Entities defined in the XML MetaData stored in OData Feeds.
  • Generate c# code classes, classes with init-only properties of c#8 and records.
  • Generate typescript code as a single file or multi files(modules).
  • Generation is based on the Metadata of the service stored on the server/ EDMX xml files or xml string contents.
  • Support http(s) with/without authentication. The Supported autherizations are: basic, token and Oauth2.
  • Console CommandLine tool Support .NET472 or higher.
  • Class library Support NET6/netstandard2.0/net461.
  • Support Windows or Linux /OS fx (with mono installed) and NET6 (netcore).
  • Packaged as a nuget package in three different packages:
  • A Class library full framework/ netstandard2.0 /NET5 for programming.
  • A console CommandLine tool (one executable file o2pgen.exe)
  • Global net core support NET6 (dotnet-o2pgen).
  • Console tool o2pgen is published as a Chocolatey package.
  • Generating CSharp POCO classes. Other languages may be added in the near future based on the community needs.
  • Convert Data type of EDMX to the corresponding CLR data types.
  • Support Entites, complex data type, Collections and navigation properties.
  • Support OData service version V1..V4
  • Code generation is controlled by setting different options:
    • Add the following attributes: - Add Key Attributes. - Add Required Attributes to the properties. - Add JsonProperty Attribute to the properties. - Add Table Attribute to the class. - Add DataMember Attribute to the properties and DataContract Attribute to the class. - Add display attribute to the properties. - Add ProtoMember to the properties and ProtoContract to the class to suport Proto Buffer. - Add user defined attribute for the properties.

    • Adding virtual modifier to the properties.

    • Convert name of properties to camelCase or PasCase

    • Add nullable datatypes, e.g. int?.

    • Generate (or not) navigation properties.

    • Generated class follows inheritance hierarchy of OData feed (unless switched-off).

    • Generated class can inherit from a common BaseClass/interface.

    • Define namespace to overwrite the namespace of the model.

    • Filter Entities.

    • Name Mapping of Entities and properties using json file with regex support.

  • Add primary key/mandatory comments to the properties of the class.
  • Rename class/properties that have a name match a c# reserved keyword.
  • Save metadata and generated code to a user defined file name.
  • Support colored console windows /linux /OS fx.
  • Support Microsoft.OData.Edm library version 7.5+ (OData v4).
  • Support Microsoft.Data.Edm library (OData v1-v3).

Features added in V3.2.0:

  • New: Support Windows NTLM authentication(Thanks to @lobster2012-user for help).
  • New: Support Microsoft Digest authentication.
  • New: Support Integrated Windows Authentication, enabling users to log in with their Windows credentials (Issue#19).
  • New: Add jsonProperty(originalName) to properties that are renamed because its name is the same as its enclosing type.
  • New: Show/hide model warning due to renaming properties/classes whose name is a reserved keyword.
  • New: Support abstract class.
  • New: support complex type inheritance
  • New: Add attribute [MaxLength] for max length of string/byte[] properties.
  • Convert EDM.TIME in Odata v3 to TimeSpan.
  • Support multi schema.
  • Support multi containers in OData v3.

OData2Poco Packages

OData2Poco is available in three flavers:

  • A class library: support NET6/netstandard2.0/net461,download.
  • A Console tool: OData2Poco.CommandLine support net472 (a.k.a o2pgen), download.
  • A .Net Core Global tool dotnet-o2pgen support NET6, download.
  • Checolatey Console tool, download.

Install and Usage

1) OData2Poco.CommandLine o2pgen Console Cli

OData2Poco.CommandLine is a Console application (net472) named o2pgen.

It Can be installed from Nuget Gallery:

   Install-Package OData2Poco.CommandLine 

Executing o2pgen as MsBuild Target

Add the next xml code to the project.csproj:

<Target Name="Odata2PocoRun" BeforeTargets="CoreCompile">
         <PropertyGroup>
			<EnableCodeGeneration>true</EnableCodeGeneration>
               <o2pgen>$(PkgOData2Poco_CommandLine)\tools\o2pgen.exe</o2pgen>
               <options>-r http://services.odata.org/V4/Northwind/Northwind.svc/ -f Model\north.cs</options>
		</PropertyGroup>
		<Message Text="Executing o2pgen.exe" Importance="High" />
		<Exec Condition="$(EnableCodeGeneration)
             Command="$(o2pgen)  $(options)" />
</Target>

The attribute Options is the commandLine arguments. Modify the commandline options as you want. For more details read Getting Start.

Excuting o2pgen from Package Console Manager (PCM):

In visual studio 2019 and higher, o2pgen can be run directly from PowerShell Console (PCM). Its path is set during installation.

Check application is installed:

PM> o2pgen --version

Linux and Mac/OS x support

O2pgen cli can run on Linux and Mac/OS if Mono is installed.


2) OData2Poco global Console Cli (net6.0)

Install from nuget gallary, run the command:

dotnet tool install --global OData2Poco.dotnet.o2pgen

How to use:

Run the command:

   dotnet o2pgen -r http://services.odata.org/V4/Northwind/Northwind.svc/
   

For help type: dotnet o2pgen --help

Review Commandline option.

Executing the global tool as Msbuild Target

You can auto run dotnet o2pgen from within MsBuild Target and save code in the project folder.

Add the next Msbuild target to your project and modify command parameters as needed. When the property EnableCodeGeneration is set to false, no code is generated. The generated code is saved to file northwind.cs in the folder Model in the root of the project.

<Target Name="GenerateCode" BeforeTargets="CoreCompile">
		<PropertyGroup>
			<EnableCodeGeneration>true</EnableCodeGeneration>
		</PropertyGroup>
		<Exec  Condition="$(EnableCodeGeneration)"
		  Command="dotnet o2pgen -r http://services.odata.org/V4/Northwind/Northwind.svc/ -f $(MSBuildProjectDirectory)\Model\northwind.cs -B">
		</Exec>
	</Target>

3) OData2Poco Class library

Support NET6/netstandard2.0/net461. It can be installed from Nuget Gallery

     Install-Package OData2Poco

Try demo Application in NET6 Online


4) Checolatey Package

From Chocolatey Gallery:

 choco install odata2poco-commandline

Documentation

Read the:Wiki


License

MIT License.


Release Notes

Changes


Acknowledgements:

Thank you JetBrains for Resharper open source license

  • .NETFramework 6.0: 6.0.0.0

Owners

moh-hassan

Authors

Mohamed Hassan

Project URL

https://github.com/moh-hassan/odata2poco

License

Unknown

Tags

code-generation odata charp c# typescript ts dto poco AspNetWebApi WebApi

Info

0 total downloads
0 downloads for version 5.1.0-dev-36
Download (1.15 MB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
5.1.0-dev-36 1.15 MB Mon, 21 Nov 2022 10:42:38 GMT 0
5.1.0-dev-35 1.15 MB Fri, 18 Nov 2022 12:51:34 GMT 0
5.1.0-dev-34 1.15 MB Fri, 18 Nov 2022 07:56:31 GMT 0
5.1.0-dev-33 1.15 MB Tue, 18 Oct 2022 22:13:57 GMT 0