Code First Northwind Data Service

This sample uses the WCF Data Service and Entity Framework 4.1 to create an OData service that exposes data from the Northwind sample database by using the new Code First functionality in Entity Framework.

C# (833.6 KB)
 
 
 
 
 
4.7 Star
(3)
6,722 times
Add to favorites
2/23/2012
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Typos in read me/description
    2 Posts | Last post February 23, 2012
    • Hello Glenn, 
      First of all, thanks for putting this together. 
      
      Readme file/Description tab above says "Because DbContext inherits from ObjectContext, you can use DbContext as the data source for a data service using the Entity Framework provider"
      
      Is this a typo? Cause I don't see that DbContext inherits from ObjectContext. So the whole sentence is misleading. Secondly, your project uses port number 12345, where as the readme suggests to browse url using port 54321 :).
      
      Also, do you have any other reference implementation that includes best practices?
      
      Thanks
      Randhir
    • Thanks for catching that! 
      We have some additional guidance for OData on Azure here: http://msdn.microsoft.com/en-us/library/hh689718(v=vs.103).aspx#efprovider
  • How to insert data?
    2 Posts | Last post July 08, 2011
    • Hello!
      How to insert data with code first Northwind data service?
    • You should be able to insert data into the data service as you normally would for an OData service, such as by using the WCF Data Services client library, as shown here: http://msdn.microsoft.com/en-us/library/dd756361.aspx.
      
      Have you had problems doing this?
  • Custom WebGet Method
    2 Posts | Last post July 08, 2011
    • I like the sample code and everything works fine, BTW I am new to .NET WCF Data Services. However, when I added custom method as shown here http://msdn.microsoft.com/en-us/library/dd744841.aspx#Y403, I get following error "Internal Server Error. The type 'System.Data.Entity.DynamicProxies.Orders_...' is not a complex type or an entity type". This is because I have public virtual ... property.
      Is it possible to have WebGet methods without loosing entity relation?
    • The service operation can only return types that are primitives (e.g. string, int, bool) or entity types, which are defined in the data model. You will need to add the type you want to return to your data model, or you could serialize some custom type and return it as a string (but then you have to deserialize it on the other end and it won't be tracked by the WCF Data Services client library).