I published a WebAPI service that returns a list of items. I use Breeze, and I was able to mostly work with filtering / sorting. However, Expand does not work.
http://www.ftter.com/desktopmodules/framework/api/dare/dares?$expand=ToUser
In the answer above, you can see ToUserId ForeignKey, but the ToUser properties are NULL (user definitely exists)
In the metadata, you can see the ToUser EF navigation property.
When I use .Include on the server side, I can populate it with EF, but I do not want to do this.
I checked Breeze Tutorial 2 here on Expand: http://learn.breezejs.com/ Here it is without an extension: http://learn.breezejs.com/api/northwind/Products
and here it is with Expand (And you can see more information about the category): http://learn.breezejs.com/api/northwind/Products? $ expand = Category
This is what I am trying to do, but mine does not fill it ...
UPDATE: I downloaded Breeze 1.3.6 Samples and downloaded the DocCode solution in VS2011. I launched it and saw that the client side is expanding; e.g. http://localhost:47595/breeze/Northwind/Orders?$top=1 (without extension) http://localhost:47595/breeze/Northwind/Orders?$top=1&$expand=Customer (expanding the client correctly) .
I checked the WebAPI controller code and it looks the same, except that they use EF Code First instead of Model First. The foreign key is decorated with the property:
An example of a breeze that works
[ForeignKey("CustomerID")] [InverseProperty("Orders")] public Customer Customer {get; set;}
It just doesn't make sense ... it has something to do with my WebAPI controller or EntityFramework ...
UPDATE 2 I downloaded the simplest ToDo Knockout Breeze example and added this line to the ToDoItem class: public User ToUser { get; set; } public User ToUser { get; set; } public User ToUser { get; set; } Then I can expand the WebAPI call with http://localhost:63030/breeze/todos/Todos?$expand=ToUser
So, I came to the conclusion that this is due to the fact that I use EntityFramework DB first, not Code First. This definitely seems possible in the current version of WebAPI with Breeze and EF.
UPDATE 3 I narrowed it down to my database, the first data from EF Database First and Code First, but still haven't identified the problem. I changed from Model approach to Code First with the same result (i.e. No extension).
For example: if you look at this expand on the Breeze site that works, http://learn.breezejs.com/api/northwind/Products?%24expand=Category , try changing the last parameter to an invalid field and it causes an error, for example : http://learn.breezejs.com/api/northwind/Products?%24expand=Category1
However, in my code, it always ignores this parameter and returns ALL records, and never throws an exception if the Expand parameter is incorrect: http://www.ftter.com/desktopmodules/framework/api/dare/dares?$expand=To4657657User
Therefore, I am at a standstill. I have no idea why this is not working.
My code
[HttpGet] [Queryable(AllowedQueryOptions = AllowedQueryOptions.All)] public HttpResponseMessage Dares() { var response = Request.CreateResponse(HttpStatusCode.OK, (IQueryable<Dare>)contextProvider.Context.Dares); return ControllerUtilities.GetResponseWithCorsHeader(response); }
and here is the generated class from my EF model (using the First database)
public partial class Dare { public int DareId { get; set; } public int ToUserId { get; set; } public virtual User ToUser { get; set; } }