OData / WebApi

OData Web API: A server library built upon ODataLib and WebApi
https://docs.microsoft.com/odata
Other
853 stars 476 forks source link

Support C# interface to edm model builder #888

Open xuzhg opened 7 years ago

xuzhg commented 7 years ago

C# interface can't work now in the latest product codes.

Here's a proposal how to implement the interface in Web API OData:

For example:

public interface IA
{
    int AProp {get;set;}
}

public interface IB
{
   string BProp {get;set;}
}

public abstract class C
{
    public string CProp {get;set;}
}

public class class D : C, IA, IB
{
   public string DProp {get;set;}
}

So, type D should have a based type of C, and two implementions for the interface IA and IB.

In OData, the implementor for IA and IB should be used as annotation for the type of D.

for example (prototype):

<EntityType Name="C" Abstract="True">
  ...
</EntityType>
<EntityType Name="D" BasedType="C" >
   ....
   <Annotation Name="Core.Implementation" Value="NS.IA, NS.IB" />
</EntityType>

<ComplexType Name="IA" >
   ...
</ComplexType>
<ComplexType Name="IB">
  ...
</ComplexType>

Where, the IA and IBare reserved as Complex type.

Then, we can do:

Get ~/odata/Ds(key)/DProp
Get ~/odata/Ds(key)/CProp       //success. because D has the whole properties from base type
Get ~/odata/Ds(key)/Ns.C/CProp  // Success.
Get ~/odata/Ds(key)/AProp      // failed. because D doesn't have the property from interface.
Get ~/odata/Ds(key)/NS.IA/AProp  // success.
Get ~/odata/Ds(key)/NS.IB/BProp  // success.

A lot of customers are asking for the support for the interface. So . please do some investigation.

xuzhg commented 7 years ago

@mikepizzo

Hi, Mikep, do we have the similar annotation defined in the Core annotation?

Jamaxack commented 5 years ago

Any updates?

weitzhandler commented 4 years ago

Related: https://github.com/OData/odata.net/issues/1746

weitzhandler commented 4 years ago

@xuzhg

Where, the IA and IBare reserved as Complex type.

How will clients (such as ODataConnectedService) identify IA and IB as interfaces?

komdil commented 3 years ago

any progress?