I am "successfully" executing a breeze query against an asp.net web api ODATA service, but there doesn't seem to be any children, even though the response has the children in it.
query: var query = breeze.EntityQuery.from('Transactions') .take(20) .orderBy('Transaction_Timestamp desc') .expand('Items');
How do I access the children? I have tried .Items, .Items(), .Item, .Item(), there is no property or method there. On the service side, I verified that there are navigation properties from Transaction to Items (Transaction.Items), and Items.Transaction. And, as I said, the http response from the service has all of the children's data.
Where can I look to see where the problem might be?
Breeze config:
breeze.config.initializeAdapterInstance('dataService', 'webApiOData', true);
$http.defaults.headers.put = {
'Access-Control-Allow-Origin': '*'
};
new breeze.ValidationOptions({ validateOnAttach: false }).setAsDefault();
var metadataStore = createMetadataStore();
etc.
My Transaction class:
public partial class Transaction
{
public Transaction()
{
this.Discounts = new HashSet<Discount>();
this.Items = new HashSet<Item>();
this.Tenders = new HashSet<Tender>();
}
public System.Guid Id { get; set; }
...
public virtual ICollection<Item> Items { get; set; }
}
My Item class:
public partial class Item
{
public System.Guid Id { get; set; }
public System.Guid Transaction_Id { get; set; }
...
public virtual Transaction Transaction { get; set; }
}
Would this not be enough?
odata/$metadata for Item entity:
<EntityType Name="Item">
<Key>
<PropertyRef Name="Id"/>
</Key>
<Property Name="Id" Type="Edm.Guid" Nullable="false"/>
<Property Name="Transaction_Id" Type="Edm.Guid" Nullable="false"/>
... (omitted fields)
<NavigationProperty Name="Transaction" Relationship="TransactionService.Models.TransactionService_Models_Item_Transaction_TransactionService_Models_Transaction_TransactionPartner" ToRole="Transaction" FromRole="TransactionPartner"/>
</EntityType>
This is data returned in the Transactions.Expand('Items') breeze query:
{
"odata.metadata":"http://localhost:49858/odata/$metadata#Transactions","value":[
{
"odata.type":"TransactionService.Models.Transaction","odata.id":"http://localhost:49858/odata/Transactions(guid'f93805cf-cc80-4d2e-9d9e-97df9c21c622')","[email protected]":"http://localhost:49858/odata/Transactions(guid'f93805cf-cc80-4d2e-9d9e-97df9c21c622')/Discounts","[email protected]":"http://localhost:49858/odata/Transactions(guid'f93805cf-cc80-4d2e-9d9e-97df9c21c622')/Shift","[email protected]":"http://localhost:49858/odata/Transactions(guid'f93805cf-cc80-4d2e-9d9e-97df9c21c622')/Tenders","[email protected]":"http://localhost:49858/odata/Transactions(guid'f93805cf-cc80-4d2e-9d9e-97df9c21c622')/Items","Items":[
{
"odata.type":"TransactionService.Models.Item","odata.id":"http://localhost:49858/odata/Items(guid'511348d7-2886-4b13-ad7e-0eeb2a11bd85')","[email protected]":"http://localhost:49858/odata/Items(guid'511348d7-2886-4b13-ad7e-0eeb2a11bd85')/Transaction","[email protected]":"Edm.Guid","Id":"511348d7-2886-4b13-ad7e-0eeb2a11bd85","[email protected]":"Edm.Guid","Transaction_Id":"f93805cf-cc80-4d2e-9d9e-97df9c21c622","[email protected]":"Edm.DateTime","Updated":"2014-05-06T20:30:30.657","[email protected]":"Edm.Int16","Ordinal":1,"Item_Type":"item ","Item_Number":"39 ","Parent_Ordinal":null,"[email protected]":"Edm.Byte","Modifier":0,"Description":"Cinnamon Coffee Cake","Item_Serial":null,...
etc...
Items
show up in the JSON that it is of typeItem
to map it properly. – PW Kad