The Project has moved to GitHub https://github.com/moh-hassan/odata2poco

 

Generate "plain-old" CLR objects (POCO) Classes from OData Service
OData2Poco is a class library with T4 Template to generate  plain-old CLR objects (POCO) from OData feeds (V1..V4). POCO classes can be used in typed RESTful client OData services.

News

June 24,2016

OData2Poco and o2pgen  V 2.0.0 is ready , with new features

- Add Class PocoSetting for managing code generation
- Add KeyAttribute to the property
- Add RequiredAttribute to the property
- Add TableAttribute to the class
- Add Navigation properties to the class
- Add Nullable DataTypes to the  properties.
- Add more options for o2pgen commandline tool
- Re-factoring code for portability readiness.

 

May 2,2016

OData2Poco.CommandLine tool (o2pgen) is  available for download  or install from nuget
  For more details read

Why POCO for OData

OData protocol exposes domain-specific resources over HTTP and is primarily designed to work with Entities.

Simply, OData is a REST service with awareness of entity data model.

The developer can perform necessary conversions of both OData query strings (which is json format) and query results in POCO objects using Typed API of the HTTP client tools.

Using POCO , which is a real representation of the data type, developer can interact with Client APIs in a strongly typed manner leading to a productive end-to-end type-safe communication gateway from client to server.

POCO, can be annotated with Attributes like [Key],[Required] , use Nullable data types and use validation that help in CRUD operations (POST/GET/PUT/DELETE verbs).

Features of OData2PocoLib:

  • Generate POCO classes corresponding to the Entities defined in the MetaDataString. C# is only supported in this version.
  • Generation is based on the metadata of the service stored on the  server/ or EDMX xml files.
  • Support http(s) with/without basic authentication : user and password
  • Convert Data type of EDMX to the corresponding CLR data types.
  • Support Entites , complex data type ,Collections and Enum.
  • Excluding navigation properties.
  • Use List<T> For Collections.
  • Support OData service version 1..4
  • Add comments to  the properties of the class which is primary key and mandatory  in source entities.
  • Save metadata to a file.
  • T4 template is included.
  • Extract http header (for http service).
  • Can be downloaded from nuget.
  • Support .NET 4.5 or higher
  • Tested with OData feeds.

New features in v2.0.0

  • Add Class PocoSetting for managing code generation
    • Add KeyAttribute to the property
    • Add RequiredAttribute to the property
    • Add TableAttribute to the class
    • Add Navigation properties to the class
    • Add Nullable DataTypes to the  properties.
    • Add more options for o2pgen commandline tool
    • Re-factoring code for portability readiness.

The current version generates C# code . 

Download OData2Poco from CodePlex or install using OData2Poco

OData2Poco

OData2Poco.CommandLine tool

OData2Poco.CommandLine (o2pgen.exe) is a console application,  enables the developer to easily generate POCO c# clasees  from within the development environment using the Package Console Manager.

OData2Poco.CommandLine tool is  available for download or install from nuget
  For more details read

 nuget command

There is a plan to add  extra features .

 I'm waiting the feedback from the community for bug fix and extra features.

.NET Requirements:
OData2Poco requires .Net 4.5 or higher.  

Dependency

  • Microsoft.Data.Edm  version="5.7.0"  or higher
  • Microsoft.OData.Edm  version="6.15.0" or higher

note: The generated POCO classes code need not these EDM dependency libraries when POCO is used in your project.

Release Notes

Current version 1.3.0

 How to use

Read the documentation

 

Source Code

Source code can be viewed  in  github. I hope of getting more people to collaborate on the project.

 

Give it a try

you can use for test the open published OData service,

for V4: http://services.odata.org/V4/OData/OData.svc

for V3: http://services.odata.org/V3/OData/OData.svc

 

Sample of Generated code

for OData feed: http://services.odata.org/V4/OData/OData.svc

using System;
using System.Collections.Generic;
//uncomment for spatial data type and run Install-Package System.Spatial
//using System.Spatial;

//------------------------------------------------------------------------------

// <auto-generated>
//     This code was generated using  OData2Poco Class library.
//     Service Url: http://services.odata.org/V4/OData/OData.svc
//     MetaData Version: 4.0
// </auto-generated>
//------------------------------------------------------------------------------

namespace ODataDemo
{
    public class Product
    {
                public int ID {get;set;}  //PrimaryKey not null
                public string Name {get;set;}
                public string Description {get;set;}
                public DateTimeOffset ReleaseDate {get;set;}  // not null
                public DateTimeOffset DiscontinuedDate {get;set;}
                public short Rating {get;set;}  // not null
                public double Price {get;set;}  // not null
    }
.......

Review the complete generated code for the service

.....
  

}

 


 

Last edited Jul 5 at 9:28 AM by mohamed_hassan, version 46