使用Breeze在没有数据库的情况下扩展属性(NoDb) [英] Expand properties using Breeze with no database (NoDb)

查看:85
本文介绍了使用Breeze在没有数据库的情况下扩展属性(NoDb)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过创建自定义元数据定义并将其添加到微风实体管理器,我已经成功地将微风连接到服务器上的自定义类型。



但是,我无法请求在javascript中已自定义的对象(员工)并无法完全检索其关系。



换句话说,我有一个名为Employee的对象,该对象具有一个名为 LoginStats的属性,该属性是服务器上的列表类型。当使用Breeze请求该对象时,集合中应该只有6个元素返回。



$ promise的结果如下:

  data.results [0] .loginStats()[0] //对象
data.results [0] .loginStats()[ 1] //未定义

如果我分别选择属性,例如.select( LoginStats )它返回完整的数组中的6个项目。



我如何在不使用任何微妙拼写出所有所需属性的情况下检索该对象呼叫?我试图使用.expand()子句,但不幸的是,我们没有以使这项工作有效的方式连接到EntityFramework。



谢谢!!

p>

编辑:以下是其外观示例当我使用选择语句而不是仅请求对象时。这些图像还演示了当我选择所有属性时会发生的情况,即它们都正确填写,但是不再可观察。

控制器代码:

  [HttpGet] 
公共IQueryable< Employee> Get(字符串ID)
{
var standard = new Criterion< Employee,bool>(e => e.CustomerId == id);
var loginStatisticsExtendedProperty = new FillEmployeeLoginStatistics(_UserRoleProvider,_CustomerLoginStatsViewModelRepository);
var availableCompaniesForEmployess = new AvailableCompaniesForEmployess(_CompanyAffiliatesRepository);
return _EmployeeRepository.Find(条件,loginStatisticsExtendedProperty,_EmployeeDetailsExtendedProperty,availableCompaniesForEmployess);
}


解决方案

没有看到服务器端的内容您正在调用的控制器方法很难确定。但是我有一些建议。



首先请确保您的控制器方法返回一个IQueryable集合。仅当您要使用客户端查询进一步限制资源时才需要。通常,您可以通过在返回集合之前简单地添加一个.AsQueryable()调用来使任何集合成为IQueryable。



第二, expand语法仅对EF支持的IQueryable起作用。但是,您仍然可以从客户端返回对象图,只要它们与父对象一起序列化即可。对于 no db类型的资源,这通常意味着您要在服务器上强制解析要向下发送给客户端的所有导航属性。如果添加JsonResultsAdapter,则实际上可以通过在 visitNode方法内部进行断点来调试到正在序列化到客户端的内容。



如果不够,请发布您的控制器方法定义。


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);
        }

解决方案

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.

这篇关于使用Breeze在没有数据库的情况下扩展属性(NoDb)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆