WebApi icon indicating copy to clipboard operation
WebApi copied to clipboard

Support for generic types in EDM

Open weitzhandler opened this issue 4 years ago • 3 comments

Please add support for generic types in the EDM model generated metadata.

My model has an intermediate generic abstract base class that looks like this:

public abstract class DynamicFieldValueBase { }

public abstract class DynamicFieldValueBase<T> : DynamicFieldValueBase
{ 
  public T Value { get; set; }
}

public class TextDynamicFieldValue : DynamicFieldValueBase<string> { }

The edm for the intermediate generic class gets the following EDMX:

<ComplexType Name="DynamicFieldValueBase_1OfT" BaseType="MyProject.Data.DynamicFieldValueBase" Abstract="true">
  <Property Name="Value" Type="MyProject.Data.T" />
</ComplexType>
<ComplexType Name="T" />

Assemblies affected

  • Microsoft.OData.Edm
  • Microsoft.OData.Core ?

Reproduce steps

Try exposing a generic type throughout the EDM model.

Expected result

A generic type edm entity

Actual result

The generic entity isn't recognized as such and is generated as a non-generic entity.

Migrated from here.

weitzhandler avatar Apr 08 '20 01:04 weitzhandler

@weitzhandler could you please share how you build the model that results in the CSDL that you have shown. As of today, the standard does not support generic types. Seeing how you build the model will help to understand what happens in the mapping from C# to CSDL.

xtofs avatar Apr 14 '20 16:04 xtofs

I undid everything having generics, but it was working in such way that I exposed DynamicFieldValueBase as an entity type in the EDM.

weitzhandler avatar Apr 15 '20 17:04 weitzhandler

Are there any plans to support generics?

Xriuk avatar Nov 21 '23 17:11 Xriuk