Reputation: 145
I'm just starting out with BreezeJS and using the HotTowel template with Asp.Net Web Api and EF
I've got to the point of trying to retrieve a record using manager.getEntityByKey, using the example at http://www.breezejs.com/documentation/querying-locally
To test I'm using the code:
var key = new breeze.EntityKey("LibraryItemCategory", 1);
var entity = manager.getEntityByKey(key);
But when the code is called I get the error 'The 'entityType' parameter must be an instance of 'EntityType' ' for the first line of code.
At the point the code is called the manager has the "LibraryItemCategory" entities loaded, and I have used Visual Studio to confirm the entityType shortName is "LibraryItemCategory"
Can anyone suggest what is wrong in the code or how I can get past this?
Thanks
Mark
Upvotes: 0
Views: 1058
Reputation: 145
Finally figured it out, I had forgotten to 'Prime' the app by calling Metadata from the server so Breeze didn't understand what the type was
Upvotes: 0
Reputation: 17863
The problem is that the EntityKey
constructor's first parameter must be an instance of EntityType
, not the name of the type. See the API doc.
Therefore, you'd do something like this
var type = manager.metadataStore.getEntityType("LibraryItemCategory");
var key = new breeze.EntityKey(type, 1);
var entity = manager.getEntityByKey(key);
A bit clunky.
You might wonder Why doesn't EntityKey
accept the name of the type and use that to find the EntityType
?
Well ... it can't ... because the EntityKey
"class" has no way to discover your EntityTypes; all EntityType info is held in a MetadataStore
... of which there could be many.
We have to get the type from a MetadataStore
; in this example we get it from the manager's metadataStore
.
p.s.: you must have populated manager.metadataStore
before calling this code, either implicitly as a side-effect of your first query or explicitly as when you call fetchMetadata
.
Upvotes: 1