, ,

Just the other day, I came across a situation where I had to  quickly throw together an OData endpoint without EF.  Scratched my head for a second then realized that HttpConfigurator MapODataServiceRoute extension method simply needs an EdmModel instance.  So I tried supplying it with a dummy and it worked just find.  Below, I’ll show the Model, WebApi configuration and the REST client at work .

my Tweet model

[DataContract]     public class Tweet    


public Tweet(string link, string heading, string content)        


ExternalLink = link;            

Heading = heading;            

Content = content;        


[DataMember(Name = "ExternalLink")]        

public String ExternalLink { get; set; }        


[DataMember(Name = "Content")]        

public String Content { get; set; }        


[DataMember(Name = "Heading")]        

public String Heading { get; set; }        


public int Id { get; set; }  // model is required to have a key. thats the only downside affecting my POCO

addition to WebApiConfig.cs file

ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();            

var tweets = modelBuilder.EntitySet<Tweet>("Tweets");  

var tweet = tweets.EntityType;            

tweet.HasKey(p => p.Id);            

tweet.Property(p => p.Heading);            

tweet.Property(p => p.ExternalLink);            

tweet.Property(p => p.Content);            


config.MapODataServiceRoute("odata", "odata", modelBuilder.GetEdmModel());


and REST client testing the OData endpoint 🙂