I have a number of entity types that use the identical ResourceNames but are different in dataProperties fields and query where clause using 'ContentTypeId' (see code below).
In the last function listed (getCorrespondenceDocuments), if I use the entity type name 'Correspondence' in the from clause, Breeze ignores the defaultResourceName value provided and constructs the OData query using the entity type name as the resourcename string:
/_api/Correspondence?$filter=ContentTypeId%20eq%20'0x01...22'&$select=Id%2CTitle%2CContentTypeId%2CCreated%2CModified%2CCorrespondenceType%2CCorrespondenceDate%2CCorrespondenceAuthor%2CCorrespondenceRecipient%2CCorrespondenceTopic%2CConfidentialFlag%2CFile&
If I use the defaultResourceName in the from clause, Breeze will construct the OData request using the default document entity and the correct resourcename string but it does not include the correct dataProperties fields:
/_api/SP.AppContextSite(@target)/web/lists/getByTitle('Documents')/items?@target='http://my.spserver.com/dev/JDP'&$expand=File&$filter=ContentTypeId%20eq%20'0x01...22'&$select=Id%2CTitle%2CContentTypeId%2CCreated%2CModified%2CFile%2CConfidentialFlag&
I also tried using the .toType('Correspondence') method to the last test. No fields are returned at all:
/_api/SP.AppContextSite(@target)/web/lists/getByTitle('Documents')/items?@target='http://my.spserver.com/dev/JDP'&$expand=File&$filter=ContentTypeId%20eq%20'0x01...22'&
It appears that Breeze is assuming that your resource name will be different for each entity type.
How do I tell Breeze to use the correct entity data properties and resource name?
// Document type (default document type)
function addDocumentType() {
addType({
name: 'Document'
, defaultResourceName: 'SP.AppContextSite(@target)/web/lists/getByTitle(\'Documents\')/items?@target=\'' + spContext.hostWeb.url + '\'&$expand=File'
, dataProperties: {
Id: { type: breeze.DataType.Int32 }
, Title: { nullable: true }
, ContentTypeId: {}
, Created: { type: breeze.DataType.DateTime }
, Modified: { type: breeze.DataType.DateTime }
, File: { complexType: 'Document:#File' }
, ConfidentialFlag: { type: breeze.DataType.boolean, nullable: true }
}
});
}
// Correspondence type
function addCorrespondenceType() {
addType({
name: 'Correspondence'
, defaultResourceName: 'SP.AppContextSite(@target)/web/lists/getByTitle(\'Documents\')/items?@target=\'' + spContext.hostWeb.url + '\'&$expand=File'
, dataProperties: {
Id: { type: breeze.DataType.Int32 }
, Title: { nullable: true }
, ContentTypeId: {}
, Created: { type: breeze.DataType.DateTime }
, Modified: { type: breeze.DataType.DateTime }
, CorrespondenceType: { nullable: true }
, CorrespondenceDate: { type: breeze.DataType.DateTime, nullable: true }
, CorrespondenceAuthor: { nullable: true }
, CorrespondenceRecipient: { nullable: true }
, CorrespondenceTopic: { nullable: true }
, ConfidentialFlag: { type: breeze.DataType.boolean, nullable: true }
, File: { complexType: 'Document:#File' }
}
});
}
function getDefaultDocuments(page) {
return breeze.EntityQuery
.from(documentType.defaultResourceName)
.orderBy('Id')
.skip(pageSize * (page - 1))
.take(pageSize)
.using(manager)
.execute()
.then(function (data) {
return data.results;
});
}
function getCorrespondenceDocuments() {
return breeze.EntityQuery
.from('Correspondence')
//.from(correspondenceType.defaultResourceName)
.where('ContentTypeId', 'eq', breeze.config.contentTypeIds.correspondence)
.using(manager)
.execute()
.then(function (data) {
return data.results;
});
}