entity framework 5 - Can't seem to expand an Image Navigation property with Breeze JS -


i using mvc, entity framework, durandal , breeze js. i've got user looks such (simplified):

public class user : entitybase<guid>, iaggregateroot {     public guid id { get; set; }     public string username { get; set; }     public string firstname { get; set; }     public string lastname { get; set; }      [foreignkey("userimage")]     public virtual guid? imageid { get; set; }      public virtual userimage userimage { get; set; } } 

the userimage class looks such. know should limit size of image. (maybe issue?):

public class userimage {     public guid id { get; set; }      [maxlength]     public byte[] image { get; set; }         } 

i've got api function on server current user:

public iqueryable<user> getcurrentuser()     {         iprincipal principal = httpcontext.current.user;         var users = _uow.users.findby(u => u.username.equals(principal.identity.name));         if (!users.any())         {             throw new httpresponseexception(request.createresponse(httpstatuscode.unauthorized));         }          return users;     } 

and 2 calls on client current user. first in shell:

function loadcurrentuser() {         return uow.currentuser.all().then(function (newuser) {             log('welcome site ' + newuser[0].fullname() + '!', newuser[0], true);             config.currentuser(newuser[0]);             return true;         });     } 

the second in manageuser viewmodel:

function activate() {                     return uow.currentuser.all(['userimage']).then(function (user) {                         self.currentuser(user[0]);                         return $.when(init()).then(boot());                     }).fail(function() {                         return router.activate('accounts/login');                     });                 } 

now can load image manageuser page , save , in fiddler shows imageid , image being sent across server. checked beforesaveentity intercept , shows 2 entities being saved.

  1. updated user imageid set
  2. new userimage

the data visible in database. when refresh manage user page can see 2 getcurrentuser calls in fiddler.

  1. from shell call can see user being returned , imageid set no userimage sent on because didn't expand query.
  2. from manage user call see user returned imageid sent on , image object omitted json.

has come across issue images? other expands appear working correctly. have examples on using breeze save filepath image , possibly using windows azure media storage?

i know won't answer question propose not sending byte array client , rather have image handler on server side takes imageid parameter , return image relevant content type set. example of can found here.

by using approach reference image html using img tag source set image hander relevant imageid.

an example using knockout data binding be:

<a data-bind="attr: {href: '/image/' + user.imageid()}"></a> 

this approach enables add caching on both server , client improve performance. removed need convert byte array image on client side, may or may not pain.

edit:

when saving managed user, post image upload action on imagehandler (have @ this article). action must return new id of image. after you've received new id, update user.imageid on client side , call savechanges on breeze.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -