Breeze filtering not working - filter

I am using breeze and the filter does not work.
var EntityQuery = breeze.EntityQuery;
var manager = configureBreezeManager("xxx");
function configureBreezeManager(param) {
breeze.NamingConvention.camelCase.setAsDefault();
var mgr = new breeze.EntityManager(param);
model.configureMetadataStore(mgr.metadataStore);
return mgr;
}
And my query query
var query = EntityQuery.from('GetStudents').where("Id", "==", "xxx");
return manager.executeQuery(query)
The filter is ignore and all results are returned. my get student returns an IQueryable of all students.
public IQueryable<Students> GetStudents(){
return context.Students;
}
Is there something up there I am doing wrong or should I look elsewhere?
EDIT
I realize that my controller is missing the property [BreezeController]. But when I include that, me metadata path is not found giving me an error (error 500 below) when trying to load it. The matadata loads fine without this property on the controller, but filtering does not work. Is this related?
"Could not load file or assembly 'System.Web.Http.OData, ... or one of its dependencies. The system cannot find the file specified."

Your issue might be that you have specified a 'camelCase' namingConvention, but your query is for 'Id' instead of 'id'. i.e. try:
var query = EntityQuery.from('GetStudents').where("id", "==", "xxx");
return manager.executeQuery(query)

I was missing the [BreezeController] and after adding it, I received the error Could not load file or assembly System.Web.Http.OData, Version=4.0.0.0 and was able to solve it by runing Install-Package Microsoft.AspNet.WebApi.OData in the package manager

Related

Parse Query using Geoquery

I'm running queries on some objects with linked geoquery data.
However, none of the queries work and return the following error
location object expected, location array not in correct format
Console logs show that
gp is definitely an object, is definitely a Parse Geopoint and has correct coordinates.
I'm stumped, any advice appreciated
let gp = null;
if (search.hasOwnProperty("geo")) {
console.log(`Geodata ${JSON.stringify(search.geo)}`);
gp = new Parse.GeoPoint({
latitude: search.geo.lat,
longitude: search.geo.long
});
console.log(`GP type ${typeof gp}, GP ${JSON.stringify(gp)}`);
let query = new Parse.Query("Place");
query.near("location", gp);
query.find({
success: (e) => console.log(`Geo near query ${JSON.stringify(e)}`),
error: (e) => console.log(`Geo near error ${JSON.stringify(e)}`)
});
};
I created something on my side that work with the following code:
let gp = new Parse.GeoPoint({
latitude: 37.337845,
longitude: -122.037687
});
// 1. first run this in order to save some location to your DB
var LocationTest = Parse.Object.extend("LocationTest");
var locationObject = new LocationTest();
locationObject.set("location",gp);
locationObject.set("name","location name test");
locationObject.save().then(function(result){
},function(error){
});
// 2. Uncomment and run this query after you save the object above
/*
var query = new Parse.Query("LocationTest");
query.near("location",gp);
query.find().then(function(results){
},function(error){
}); */
Please first run the first piece of code in order to save a location to your DB and then run the second part for query what you have saved.
The reason that you are getting this error can be because your location is not saved as an object but as an array on your database or maybe because your location field is not of type PFGeoPoint
what i suggest you is maybe to first run my code above and check if it works and then maybe try to change maybe the class name or the field name in your DB and save and query from a different field.
This code works for me on parse-server 2.2.17 (the latest version) so please also check that your parse-server is up to date by running npm install on your app
With some experimentation, found that geoqueries fail if any of the objects being queried don't have geodata associated with it.
Bit more severe than just not having geodata, even if it has a geodata property, and that property is empty, it will crash.
Solution is to check that latitude and longitude exist before querying that object

request.object.id not returning in afterSave() in Cloud Code

Parse.Cloud.afterSave(function(request) {
var type = request.object.get("type");
switch (type) {
case 'inspiration':
var query = new Parse.Query("Inspiration");
break;
case 'event':
var query = new Parse.Query("Event");
break;
case 'idea':
var query = new Parse.Query("Idea");
break;
case 'comment':
break;
default:
return;
}
if (query) {
query.equalTo("shares", request.object.id);
query.first({
success: function(result) {
result.increment("sharesCount");
result.save();
},
error: function(error) {
throw "Could not save share count: " + error.message;
}
});
}
});
For some reason request.object.id is not returning the object id from the newly created record. I've tested this code out throughly and have isolated it down to the request.object.id variable. I've even successfully ran it with using a pre-existing object ID and it worked fine. Am I using the wrong variable for the object ID?
Thanks in advanced for any help!
Had this exact problem a few weeks ago.
It turned out to be a bug in Parse's newest Javascript SDK. Please have a look at your CloudCode folder - it should contain a global.json file where you can specify the JavaScript SDK version. By default, it states "latest", change it to "1.4.2" and upload your CloudCode folder again.
In case the global.json file is missing in your cloud code folder, please have a look at this thread, where I described how to create it manually.
Thanks for the reply. I found out another work around for this for version 1.6.5. I should probably also mention that my use case for this code is to increment a count column (comments count) when a new relation has been added to a particular record (post).
Instead of implementing an afterSave method on my relation class (comment), I instead implemented a beforeSave method on my class (Post) and used request.object.dirtyKeys() to get my modified columns. From there I check to see if my dirty key was comments and if it is I increment my count column. It works pretty well actually.

servicestack - caching a service response using redis

I have a servicestack service which when called via the browser (restful) Url ex:http://localhost:1616/myproducts, it works fine.
The service method has RedisCaching enabled. So first time it hits the data repository and caches it for subsequent use.
My problem is when I try calling it from a c# client via Soap12ServiceClient. It returns the below error:
Error in line 1 position 183. Expecting element '<target response>'
from namespace 'http://schemas.datacontract.org/2004/07/<target namespace>'..
Encountered 'Element' with name 'base64Binary',
namespace 'http://schemas.microsoft.com/2003/10/Serialization/'.
Below is my Client code:
var endpointURI = "http://mydevelopmentapi.serverhostingservices.com:1616/";
using (IServiceClient client = new Soap12ServiceClient(endpointURI))
{
var request = new ProductRequest { Param1 = "xy23432"};
client.Send<ProductResponse>(request);
}
It seems that the soapwsdl used is giving the problem, but I appear to have used the defaults as generated by servicestack..
Any help will be much appreciated.
Update
I was able over come this error by changing the cache code at the service end:
Code that returned error at client end:
return RequestContext.ToOptimizedResultUsingCache(this.CacheClient, cacheKey,
() =>
new ProductResponse(){CreateDate = DateTime.UtcNow,
products = new productRepository().Getproducts(request)
});
Code that works now:
var result = this.CacheClient.Get<ProductResponse>(cacheKey);
if (result == null)
{
this.CacheClient.Set<ProductResponse>(cacheKey, productResult);
result = productResult;
}
return result;
But I am still curious to know why the first method (RequestContext.ToOptimizedResultUsingCache) returned error at c# client?
But I am still curious to know why the first method (RequestContext.ToOptimizedResultUsingCache) returned error at c# client?
From what I can tell, the ToOptimizedResultUsingCache is trying to pull a specific format (xml, html, json, etc) out of the cache based on the RequestContext's ResponseContentType (see code here and here). When using the Soap12ServiceClient the ResponseContentType is text/html (not sure if this is correct/intentional within ServiceStack). So what ToOptimizedResultUsingCache is pulling out of the cache is a string of html. The html string is being returned to the Soap12ServiceClient and causing an exception.
By pulling directly out of the cache you are bypassing ToOptimizedResultUsingCache's 'format check' and returning something the Soap12ServiceClient can handle.
** If you are using Redis and creating your key with UrnId.Create method you should see a key like urn:ProductResponse:{yourkey}.html
Thanks for your response paaschpa.
I revisited the code and I was able to fix it. Since your response gave me the direction, I have accepted your answer. Below is my fix.
I moved the return statement from RequestContext to the response DTO.
Code which throws error when used via c# client (code was returning entire requestcontext):
return RequestContext.ToOptimizedResultUsingCache(this.CacheClient, cacheKey,
() =>
new ProductResponse(){CreateDate = DateTime.UtcNow,
products = new productRepository().Getproducts(request)
});
Fixed Code (return moved to response DTO):
RequestContext.ToOptimizedResultUsingCache(this.CacheClient, cacheKey,
() => {
return new ProductResponse(){CreateDate = DateTime.UtcNow,
products = new productRepository().Getproducts(request)
}
});

Issue Retrieving a Screenshot from a database

I've got a bunch of screenshots and some screenshot meta data I'm trying to display in an ASP.NET MVC 3 web application, I'm trying to retrieve the data from my databse but I get this error:
LINQ to Entities does not recognize the method 'System.Drawing.Image
ByteArrayToImage(Byte[])' method, and this method cannot be translated
into a store expression.
Here's my code:
var screenshotData = (from screenshots in db.screenshots
where screenshots.projects_ID == projectID
select new ImageInformation
{
ID = screenshots.id,
Language = screenshots.language,
Screenshot = Utility.ByteArrayToImage(screenshots.screen_shot),
ProjectID = screenshots.projects_ID
});
foreach (ImageInformation info in screenshotData)
{
this.Add(info);
}
ImageInformation is just a simple class that contains the defintion the information stored (ID, Language, Screenshot, ProjectID).
Here's my ByteArrayToImage function:
public static Image ByteArrayToImage(byte[] byteArrayIn)
{
using (MemoryStream ms = new MemoryStream(byteArrayIn))
{
Image returnImage = Image.FromStream(ms);
return returnImage;
}
}
Can anybody tell me why I receive this error when this code runs?
Thanks.
I think it's because, with LINQ-to-Entities, the code is turned into server-side query and it can't do that in this case. I don't think you can mix client-side code like this directly with L2E.
I would suspect you will have to do the conversion from byte->image after you've retrieved the data from the database as a distinct step.
You can't do the function in a LINQ to Entities query... one option:
1) have a byte[] property on the object you are instantiating (ImageInformation) and copy the data in there along with another propery to read the image from this ImageInformation object.

How do you read system jobs in Dynamics CRM?

The CRM SDK says this is possible but the following code fails. Does anyone know why?
var request = new RetrieveMultipleRequest();
var query = new QueryExpression(EntityName.asyncoperation.ToString());
query.ColumnSet = new AllColumns();
request.Query = query;
var response = _connection.Execute(request);
The error is:
<error>\n
<code>0x80040216</code>
<description>An unexpected error occurred.</description>
<type>Platform</type>
</error>
If I change the entity name to account, it works fine.
Found the answer. It appears that it doesn't like the "new AllColumns()" bit. If I specify a column list it works.

Resources