Browsed by
Tag: Entity Framework

.NET Web API OData and Entity Framework Database First: No Key defined

.NET Web API OData and Entity Framework Database First: No Key defined

When using EF database first, I came across an error: No Key defined… Turns out the generated classes are not decorated with the [Key] attribute. You can manually add them but once you generate your model(s) again, it’s all gone. There are workarounds floating across the internet to edit the T4 template(s) that generate these models, but every developer has to do that, plus I didn’t want to fiddle around with those files. Another way is to map your key(s)…

Read More Read More

.NET Web API and OData: Cannot serialize a null ‘feed’

.NET Web API and OData: Cannot serialize a null ‘feed’

Recently I came across an error when working with oData and web API. Cannot serialize a null ‘feed’. System.Runtime.Serialization.SerializationException I couldn’t really find a solution online, but it turns out i just forgot to decorate my method parameter with [FromODataUri]. [EnableQuery] public IQueryable Get([FromODataUri] ODataQueryOptions queryOptions) { … } Now you can use $expand and $select in your URL without issues.