微风-在对象#< Object>中扩展结果没有方法'getProperty'查询失败 [英] Breeze - expand results in Object #<Object> has no method 'getProperty' Query failed

查看:77
本文介绍了微风-在对象#< Object>中扩展结果没有方法'getProperty'查询失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的edmx模型中,有2个相关的表:Challenge和ChallengeNote(已经FK返回到ChallengeID)

In my edmx model are 2 related tables: Challenge and ChallengeNote (has FK back to ChallengeID)

我可以整日轻松进行

var qry = dataservice.getQuery( Challenges);

但是,每次都会失败:

var qry = dataservice.getQuery( Challenges)。expand( ChallengeNotes);

searchFailed被调用,并且是控制台中唯一的错误信息。

The searchFailed is called and is the only error information in the console.

return dataservice.execute(qry.inlineCount(true))
        .then(seachSucceeded)
        .fail(searchFailed);




  • 微风是否支持这样的关系数据?

  • 是否需要编写一些自定义代码来支持?

  • 我缺少什么?

  • 这里有相关的回答的问题,但是我已经在关注(除非我错过了什么)答案的解决方案(以及为什么我有2个上下文。配置设置在我的ContextProvider中)。
    breezejs-error-when-loading-an-实体相关数据

    Here's related answered question, but I was already following (unless I missed something) the answer's solution (and why I have the 2 context.Configuration settings in my ContextProvider). breezejs-error-when-loading-an-entity-with-related-data

    这是另一个未解决的类似问题,

    Here's another similar question that's been unanswered breeze-expand-query-fails-with-object-object-has-no-method-getproperty

    这是我的提供程序代码(想在项目中进一步使用BeforeSaveEntity重写):

    Here's my provider code (want to use the BeforeSaveEntity override further on in the project):

    public class ModelProvider : EFContextProvider<ModelEntities>
    {
        public ModelProvider()
            : base() 
        {
            this.Context.Configuration.LazyLoadingEnabled = false;
            this.Context.Configuration.ProxyCreationEnabled = false;            
        }
    }
    

    这是我的控制器代码:

    [BreezeController]
    public class DataController : ApiController
    {
        readonly ModelProvider _contextProvider = new ModelProvider();
    
        [HttpGet]
        public string Metadata()
        {
            return _contextProvider.Metadata();
        }
    
        [Queryable(AllowedQueryOptions = AllowedQueryOptions.All)]
        [HttpGet]
        public IQueryable<Challenge> Challenges()
        {
            return _contextProvider.Context.Challenges.Include(x => x.ChallengeNotes);
        }
    
        [HttpPost]
        public SaveResult SaveChanges(JObject saveBundle)
        {
            return _contextProvider.SaveChanges(saveBundle);
        }
    
        [HttpGet]
        public IQueryable<ChallengeNote> ChallengeNotes()
        {       
            return _contextProvider.Context.ChallengeNotes;
        }
    }
    

    当我浏览到URL时,其中包括相关内容实体:
    http:// localhost:53644 / breeze / data / Challenges?$ filter = Active%20eq%20true& $ top = 10& $ expand = ChallengeNotes& $ inlinecount = allpages

    When I browse to the URL, it's including the related entity: http://localhost:53644/breeze/data/Challenges?$filter=Active%20eq%20true&$top=10&$expand=ChallengeNotes&$inlinecount=allpages

    以下是来自控制器
    的数据

    Here is the data coming from the Controller

    至此,imo一切都指向服务器或客户端上的Breeze配置。

    At this point all things, imo, are pointing to Breeze configuration on either the Server or Client.

    TIA

    推荐答案

    微风绝对支持此操作,但是您需要确保您的实体框架模型已正确设置。请查看Breeze zip中的DocCode示例,以获取同时使用expand(客户端)或EF include(服务器端)子句的许多示例。

    Breeze absolutely does support this, but you do need to make sure that your Entity Framework model is set up correctly. Take a look at the DocCode sample in the Breeze zip for a number of examples of using both expand (client side) or EF include (server side) clauses.

    一个关于您的问题的猜测是您使用的是Breeze camelCasing命名约定,因此您的 expand子句应为

    One guess about your problem is that you are using the Breeze camelCasing naming convention and therefore your "expand" clause should be

    var qry = dataservice.getQuery("Challenges").expand("challengeNotes");
    

    即 challengeNotes(注意大小写)是与 ChallengeNotes的服务器端属性相对应的客户端属性的名称。为了明确起见, expand子句将客户端属性的名称作为参数,而属性名称是Breeze.NamingConvention的结果。

    i.e. "challengeNotes" (note the casing) is the name of the client side property that corresponds to a server side property of "ChallengeNotes". To clarify, "expand" clauses take the names of client side "properties" as parameters and property names are what are transformed as a result of the Breeze.NamingConvention.

    相反,在您的示例中,查询资源名称即 Challenges是服务器端资源的名称(由于将 Challenges方法标记为

    In contrast, a query resource name i.e. "Challenges" in your example is the name of the server side resource ( as a result of marking your "Challenges" method with the [HttpGet] annotation. This name is NOT affected by the NamingConvention.

    侧面说明:您的示例同时具有expand和Include子句。通常,您既可以在客户端查询中包含 expand子句,也可以在服务器上具有实体框架 Include子句,第一个优点是可以控制扩展

    Side notes: Your example has both an expand and an Include clause. Either of these is sufficient all by itself. You do not need both. In general you can either include an "expand" clause in your client side query OR have an Entity Framework "Include" clause on the server. The advantage of the first is that you can control the expand on the client, the advantage of the second is that you can insure that every query for a specified resource always fetches some related entities.

    希望对客户而言,第二个优点是您可以确保对指定资源的每次查询总是获取一些相关实体。

    Hope this helps!

    这篇关于微风-在对象#&lt; Object&gt;中扩展结果没有方法'getProperty'查询失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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