Breeze - expand results in Object #<Object> has no method 'getProperty' Query failed

余生长醉 提交于 2019-12-23 20:54:15

问题


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

I can do this in breeze all day long

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

However, this fails every time:

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

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

return dataservice.execute(qry.inlineCount(true))
        .then(seachSucceeded)
        .fail(searchFailed);
  • Does Breeze support relational data like this?
  • Does one need to write some custom code to support?
  • What am I missing?

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

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

Here's my controller code:

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

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

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

TIA


回答1:


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.

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

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.

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.

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!



来源:https://stackoverflow.com/questions/19869689/breeze-expand-results-in-object-object-has-no-method-getproperty-query-fa

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