Expand properties using Breeze with no database (NoDb)

风流意气都作罢 提交于 2019-12-11 23:36:48

问题


I've had some success managing to connect breeze to our custom types on the server by creating a custom metadata definition and adding it to the breeze entity manager.

However, I'm unable to request an object (Employee) that has been custom-defined in javascript and retrieve its relationship(s) completely.

In other words, I have an object called Employee that has a property called "LoginStats" that is a List type on the server. When requesting this object using Breeze only one element returns in the collection, when there should be 6.

The results of the $promise look like this:

data.results[0].loginStats()[0] //object
data.results[0].loginStats()[1] //undefined

Strangely, if I individually select the properties, such as .select("LoginStats") it comes back complete with the 6 items in an array.

How is it possible for me to retrieve this object without spelling out all of the desired properties using a breeze call? I've attempted to use the .expand() clause, but unfortunately we are not connected to EntityFramework in a way that makes this work.

Thanks in advance!

EDIT: Here's a sample of what it looks like when I use the "select" statement vs just requesting the object. These images also demonstrate what happens when I select all of the properties, which is that they are all filled in correctly, but they are no longer observables. Eeeek!

Controller code:

        [HttpGet]
        public IQueryable<Employee> Get(string id)
        {
            var criterion = new Criterion<Employee, bool>(e => e.CustomerId == id);
            var loginStatisticsExtendedProperty = new FillEmployeeLoginStatistics(_UserRoleProvider, _CustomerLoginStatsViewModelRepository);
            var availableCompaniesForEmployess = new AvailableCompaniesForEmployess(_CompanyAffiliatesRepository);
            return _EmployeeRepository.Find(criterion, loginStatisticsExtendedProperty, _EmployeeDetailsExtendedProperty, availableCompaniesForEmployess);
        }

回答1:


Without seeing what the server side controller method(s) that you are calling it's difficult to tell for sure. But I have couple of suggestions.

First make sure that your controller method returns an IQueryable collection. This is only required if you want to use client side queries to further restrict the resource. You can typically make any collection an IQueryable by simply adding an .AsQueryable() call before you return the collection.

Second, the "expand" syntax will only operate against EF backed IQueryables. But you can still return graphs of objects from the client providing that they 'serialize' along with the parent. For "no db" type resources this usually means that you force resolution on the server of any navigation properties that you want sent down to the client. If you add a JsonResultsAdapter you can actually 'debug' into what is being serialized down to the client by breakpointing inside of the 'visitNode' method.

Please post your controller method def's if this is insufficient.



来源:https://stackoverflow.com/questions/15689266/expand-properties-using-breeze-with-no-database-nodb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!