breeze - BreezeJS Selecting Collection -
this related question in: breezejs selecting complextype properties
so:
public class person { public int id {get;set;} public string name {get;set;} public address myaddress {get;set;} public virtual icollection<pet> pets {get;set;} }
i call
entityquery.from('person').select('id,name,pets').orderby('id');
and map personbrief object.
i know there a:
.totype("personbrief")
extension, doesn't seem "find object description" (where define this?), , online says no complex types supported.
then tried mapdtostoentities() function jumpstart hottowel tutorial
this method seems map non-array properties. dto returned breeze query has pets collection correctly populated. tried loop-pushing them ko.observablearray event though populates new entity, breeze fails "collection navigation property might not set" error.
in end create computed in initializer says.
personbrief.sumofpetages = ko.computed(function() { var sum = 0; person.pets().foreach(function (i) { sum += i.petage(); }); return sum; });
any ideea how can keep object graph after projection? thanks
did define personbrief
entitytype? i'm betting not ... given called "personbrief" in sample. totype()
method casting simple, flat, known entitytype. think you're heading off track bit here.
why not cast person
? sure of person material missing (as in ccjs ... although not in particular example in projecting data properties). it's straightforward. write totype('person')
. did try that?
if want define such entitytype on client, can as described in docs. if that, can use totype()
cast type , breeze track in cache. of course saving such thing server matter. that's doable ... kind of dto ... you'll have write interception logic on server , translate data real, server-side persistent entities , path beyond scope of answer.
here code ... written off top of head ... should point in right direction. note assuming pet
entitytype, not complextype! @ moment breeze not support arrays of complextypes (it doesn't today).
// define personbrief type given metadatastore function addpersonbrieftype(metadatastore) { var pertype = metadatastore.getentitytype('person'); var type = new breeze.entitytype({ shortname: 'personbrief', namespace: pertype.namespace }); var idproperty = new breeze.dataproperty({ nameonserver: 'id', datatype: breeze.datatype.int32, ispartofkey: true, }); type.addproperty(idproperty); type.addproperty(new breeze.dataproperty({ nameonserver: 'name' })); // here's how define pets collection // assume have pet type in metadata , // has inverse navigation person // navigation property person pets var assoc = pertype.getnavigationproperty('pets'); type.addproperty(new breeze.navigationproperty({ nameonserver: 'pets', isscalar: false, // it's collection entitytypename: assoc.entitytype.name, foreignkeynames: assoc.inverse.foreignkeynames, associationname: assoc.associationname })); metadatastore.addentitytype(type); return type; }
i able employeepartial
in metadatatests.js of doccode sample equivalent pets
orders
. comparable projection query this:
var query = breeze.entityquery.from('employees') .where('employeeid', 'eq', 1) .select('employeeid, firstname, lastname, orders') .totype('employeepartial')
your sumofpetages
computed should work because there personbrief
type supplement.
i winging myself sure. know works if can't swear particular bit of code i've written here. let know how goes you.
p.s. while should able navigate personbrief
pets
, not expect navigate pet
personbrief
; navigation property not defined.
Comments
Post a Comment