this will help The problem turned out to be an upgrade from: OData Client T4 Template ver. 2.2.0 to OData Client T4 Template ver. 2.4.0 Between the versions a few new items are added that make your old *.TTInclude files useless.
I think the issue was by ths following , Using Entity Framework I created an DbContext. The Dbcontext is created within a WebApi project. One of the tables from the DbContext represents buildings. The location is represented as a Geography type in the database. I need to query the buildings and sort the result by the distance to a given location. , You should have
public IHttpActionResult GetBuildingDistances()
var query =
Id = x.id,
Street = x.location_street,
Building = x,
Distance = x.GeoLocation.Distance(myLocation)
return Ok(query as IQueryable<BuildingDistance);
Odata v4 error "Does not support untyped value in non-open type"
Any of those help Thank you for answering me, saying that it should work, it made look harder. As Sam Xu noted, it works with the key "foo", and I tested it on my dict and it worked. It made me think that OData doens't take a number as a key, and it doesn't. I solved my problem by appending the letter 'a' in front of each year number, and know it selects just fine.
How to support a nested open complex type in the OData C# driver?
seems to work fine I'm in the same boat as you. I need to expose some data as pure JSON. This is a working solution using the ODataUntypedValue class. It serializes to what you would expect. I tested it with your models and mine. Implement a MongoDataSerializer class:
public class MongoDataSerializer: ODataResourceSerializer
public MongoDataSerializer(ODataSerializerProvider serializerProvider)
/// Serializes the open complex type as an <see cref="ODataUntypedValue"/>.
/// <param name="graph"></param>
/// <param name="expectedType"></param>
/// <param name="writer"></param>
/// <param name="writeContext"></param>
public override void WriteObjectInline(
// This cast is safe because the type is checked before using this serializer.
var mongoData = (MongoData)graph;
var properties = new List<ODataProperty>();
foreach (var item in mongoData.Document)
Name = item.Key,
Value = new ODataUntypedValue
RawValue = JsonConvert.SerializeObject(item.Value),
TypeName = expectedType.FullName(),
Properties = properties,
public class CustomODataSerializerProvider : DefaultODataSerializerProvider
private readonly MongoDataSerializer mongoDataSerializer;
this.mongoDataSerializer = new MongoDataSerializer(this);
public override ODataEdmTypeSerializer GetEdmTypeSerializer(IEdmTypeReference edmType)
if (edmType.FullName() == typeof(MongoData).FullName)
var model = builder.GetEdmModel();
b => b
.AddService(Microsoft.OData.ServiceLifetime.Scoped, s => model)
s => ODataRoutingConventions.CreateDefaultWithAttributeRouting("odata", options))