0
votes

I have all my normal breeze queries and updates working pretty perfectly and it is so awesomely slick now that I've gotten used to it!

I of course want to be difficult though, and use breeze to load entities that aren't actually the result of a query. Or at least not directly.

Basically I have another object that does some logicy stuff using my entity classes to find certain matching objects. That logic doesn't matter. The result is that calling the method on that object will return me an IEnumerable<MyObject> (actually an IList<MyObject>) that I then want to return to breeze to use on the client side. So I guess it's a query, just that something else is doing the query logic, not breeze passing it's where and orderby clauses.

However at the moment, I just get the error from breeze Object #<Object> has no method 'getProperty'

Just to explain how I've tried implementing this:

First Attempt:

[HttpGet]
public object SchemasForStatementFile(int fileId)
{
    StatementFile statementFile = _contextProvider.Context.Statements.SingleOrDefault(x => x.Id == fileId);
    IEnumerable<StatementFileSchema> schemasForFile = _parsingEngine.FindSchemasForFile(statementFile);
    return new { schemas = schemasForFile.ToArray() };
}

Second Attempt:

[HttpGet]
public IQueryable<StatementFileSchema> SchemasForStatementFile(int fileId)
{
    StatementFile statementFile = _contextProvider.Context.Statements.SingleOrDefault(x => x.Id == fileId);
    IEnumerable<StatementFileSchema> schemasForFile = _parsingEngine.FindSchemasForFile(statementFile);
    return schemasForFile.AsQueryable();
}

I get the same error with either approach.

1

1 Answers

1
votes

Great question!

This is exactly the use case for the JsonResultsAdapter. Take a look at the Edmunds sample or the 'default' JsonResultsAdapter in the source. The idea is that the JsonResultsAdapter will take the results of a query and stipulate the 'entityTypes' that it contains. It can also morph the data if needed. For more info, see here: General discussion of the JsonResultsAdapter and hereJsonResultsAdapter api.