BreezeJS Selecting ComplexType properties - javascript

I am running into an issue with Breeze and Durandal which is leading me to believe it may be a bug with Breeze or that I don't know the right syntax.
Here is my model (given that Address is just a simple ComplexType class)
public class Person {
public int Id {get;set;}
public string Name {get;set;}
public Address MyAddress {get;set;}
}
And on the front-end with Breeze JS, I have the following:
EntityQuery.from('Person').select('id,name').orderBy('id');
The above line works perfect, but if I have:
EntityQuery.from('Person').select('id,name,myAddress').orderBy('id');
I get the error message that Error retreiving data. deferred is not defined
It looks like as though, you can't have the ComplexType property in the Select statement. Anyone else is running into this issue? Thanks for your help in advance.

Edit: May 8, 2013 - This is now fixed in v 1.3.3
I've just confirmed that this is a bug - Your query syntax is correct ( you do not need an expand for complex types). I will try to get this corrected in the next release and will post back here when it gets in. And thanks for the repro :)

Related

send String from java to js, using current project

Before ask this question, I have already read the forum and tried a lot of from forum suggestions. I do not know , maybe i do not clearly understand or maybe the reason that i apply to my current project, however answer on the forum is not working in my project
Java:
#RequestMapping(value = "/warehouseWhisky", method = {RequestMethod.GET, RequestMethod.POST})
public ModelAndView viewAllWhiskyInWarehouse() {
Iterable<WhiskyDTO> list = whiskyService.seeAllWhisky();
String email = receiveEmailFromSecurity.getEmail();
System.out.println(email);
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("viewAvailableWhisky", list);
modelAndView.addObject("email", email);
modelAndView.setViewName("whisky");
return modelAndView;
}
This code correct, I recive in HTML string:
<input type="button" id="someThingNew" th:value="${email}"/>
But I didn't recieve this parameters in js:
var nameUser = $("#someThingNew").val();
console.log(nameUser);
I think the problem is caused because of the special characters in email like '#'. In other word you cannot send email address using #PathVariable (with ordinary routing configuration). Instead of #PathVariable, you can send email using #RequestParam and send it as a query parameter.
I think the first method is probably fine - just you are calling the wrong URL. What is your server mapping? I would expect something like -
http://localhost:8080/warname/warehouseWhisky/test#test.com
The issue with the second one is that its expecting similar to the following - which is why you are getting a 500
#RequestMapping(value = "/warehouseWhisky/{email}")

Speed up JSON Serialization from C# to JSON

I want to serialize my set of data to JSON.
Here is the snippet code of my ASMX to serialize the object
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetProviderMemberDetail(string jsonString)
{
BPMember bp = new BPMember();
List<BOProvider> listProvider = bp.GetProviderMemberDetail(jsonString);
return ConvertToSerializedJson(listProvider);
}
Here is what the ConvertToSerializedJson does
public string ConvertToSerializedJson(Object listBO)
{
string jsonReturn = String.Empty;
JavaScriptSerializer serializer = new JavaScriptSerializer();
serializer.MaxJsonLength = Int32.MaxValue;
jsonReturn = serializer.Serialize(listBO);
return jsonReturn;
}
The amount of data that I have to serialize is much, approximately 200.000 datas.
I have tried this method, my browser got hang and got not responding, I have to wait 6 minutes to complete.
Second attempt, I tried serializer function from Newtonsoft.Json,
added
using Newtonsoft.Json;
and changing the serializer code with
return JsonConvert.SerializeObject(listProvider);
It speed up a bit, but makes my browser almost hang too. It takes 4minutes to complete all the serialization.
The question is, how I can speed up the serialization thing? My query only takes 4seconds to finish the query execution and retrieving the data from DB. The one that take it long is the serialization process
Is there any function that will run faster than this? Please post the names library or function and the benchmark, I will update this post if I get good significant changes.
Cheers.
UPDATED
This is why I love you guys, I have speed up, with advice from you kind-guys, and here is the things that I "tweak" a little.
As #Saravanan said, I have reduced any unused (or with little frequency used) on my BO. That was a successful tweak. from 300sec (5mins) to 18sec.
As #sanguaire stated, I am trying to use fastJSON library (download here), compile to dll, add reference to my project and this speed a bit.
The times required to retrieve 200.000 datas for me is approximately 14 sec to 18 sec. This is my benchmark with 17columns.
Thank you for the opinion guys. Sorry for the late reply. I will (if my points reach the up vote standard) vote up both of your answer here.
You can find a good article on codeproject about different libraries for JSON serialization (with benchmarks).
You can find it here Article about JSON libraries
Bye.
See this:
http://aumcode.github.io/serbench/
Charts (speed and payload size):
Typical Person / single,list[100],list[5000]...
http://aumcode.github.io/serbench/Specimens_Typical_Person-201507121220/web/overview-charts.htm
Entangled Object Graph / Conferences/participants/Friends...
http://aumcode.github.io/serbench/ObjectGraph_Conference-201507121245/web/overview-charts.htm
Network Stack Batching...
http://aumcode.github.io/serbench/MsgBatching-201507121210/web/overview-charts.htm
We have also EDI X12 tests, not published yet. Get the tool and run like so:
"sb edi.laconf" it will generate the web report on disk

WebApi Method with single value and AngularJs $http json handling

I am encountering an issue and I ran out of ideas, I need some guidance towards the origin and/or the solution:
Server Side
I added the standard Microsoft Web Api Controller class "ValuesController" which looks like this:
public class ValuesController : ApiController
{
public string Get(int id){ return "value"; }
...
Client Side
In my AngularJS Controller function I have a simple get
$http({method:'GET',url: '/api/values/1'}).success(function(data){
$scope.value =data;
})
The HTML looks like this:
<input type="text" ng-model="value" />
The weird thing(the issue) is that I get: "value" in my input instead of just value (no quotes).
To avoid misunderstandings, I am getting this:
Instead of this:
And of course the questions are: why?? and how do I fix it*?
*hopefully the answer will not be returning an object instead of a simple string :)
I have the impression that this is due to security vulnerabilities in the JSON format. In the documentation of the $http service there is section called JSON Vulnerability Protection that suggests that Angular takes a few precautions to avoid an attack.
They recommend the reading of the following article: Anatomy of a Subtle JSON Vulnerability which as far as I can see delves into a case similar to yours.
Bottom line, I think you will have to return a full JSON object and not just a string. An alternative is to make sure you are getting a JSON object, by doing
$scope.value = JSON.parse(value)
The preferred (Angular provided solution) is
$scope.value = angular.fromJson(data);

Error using dynamic keyword in asp.net mvc 4

I am getting this long error when i accpet the parameter as dynamic on my server side action method in mvc 4.
{"Message":"An error has
occurred.","ExceptionMessage":"'Newtonsoft.Json.Linq.JObject' does not
contain a definition for
'TournamentId'","ExceptionType":"Microsoft.CSharp.RuntimeBinder.RuntimeBinderException","StackTrace":"
at CallSite.Target(Closure , CallSite , Object )\r\n at
System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite
site, T0 arg0)\r\n at
ManagerDeTorneos.Web.Controllers.TournamentDateController.Create(Object
data) in
F:\Prince\Projects\Juan\trunk\ManagerDeTorneos.Web\Controllers\TournamentDateController.cs:line
133\r\n at lambda_method(Closure , Object , Object[] )\r\n at
System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c_DisplayClass13.b_c(Object
instance, Object[] methodParameters)\r\n at
System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object
instance, Object[] arguments)\r\n at
System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1
func, CancellationToken cancellationToken)"}
[HttpPost]
public HttpResponseMessage AddMatch(dynamic data)
{
int tournamentDateId = (int)data.TournamentDateId.Value;
var tournamentDate = Catalog.TournamentDateRepository.GetById(tournamentDateId);
if (tournamentDate == null)
{
throw ExceptionHelper.NotFound("Fecha no encontrada!");
}
In The above method data Contains tournamentId as sent from ajax call as JSON.Stringify({'TournamentId':'5'}).
Can anybody tell me what is the cause of error. I even replaced the dll of Newtonsoft.Json as well
You are right dan but i fixed my issue by removing that dll from GAC. May be in GAC it was using old assembly
The error is caused by the fact that you typed your parameter as dynamic, which means that the model binder doesn't know what to make it. It's the same as if you were to declare it as an object. Since you are providing JSON, it serializes the object as a Json.Net JObject. Just because you define it as a dynamic doesn't mean that it's going to magically take whatever shape you need it to.
Change it to a concrete type - something that matches the structure of the provided JSON:
public class TournamentInfo
{
public int TournamentId { get; set; }
}
[HttpPost]
public HttpResponseMessage AddMatch(TournamentInfo data)
{
int tournamentDateId = data.TournamentId;
var tournamentDate = Catalog.TournamentDateRepository.GetById(tournamentDateId);
if (tournamentDate == null)
{
throw ExceptionHelper.NotFound("Fecha no encontrada!");
}
This way, the binder knows what it's supposed to turn the JSON into, and since TournamentInfo matches the structure of the JSON, it won't have any trouble serializing it.
Don't misuse dynamic. It was not introduced into C# so developers could stop defining classes.

Solution for Javascript error '_events' is null or not an object

Is any one has solution for JavaScript error '_events' is null or not an object?
Code is about 3000 line that's way I haven't put code here.Please Give me some hint so that I can put required code. I have searched on google and found two suggestion from google but not able to find solution.
I have tried latest version of AJAXControlToolkit.but not succeed.
I have trid <compilation debug="true/false">. but not succeed.
I am getting error on only one page.This page has Modelpopupextender and Radwindow and updatepanel.and error is in MicrosoftAjax.js
This error comes when
Step1: Post back page.
Step2: redirect to other page or refresh same page. and error comes.
Any help would be appreciated.
What are you using the ModalPopupExtender to accomplish? The RadWindow does much of the same functionality.
For what events in the grid are you triggering the popup window?
Given the following simple model:
public class TestModel
{
public string FileName { get; set; }
public DateTime CreateDate { get; set; }
public string UserName { get; set; }
public string Type { get; set; }
}
and a GetForGrid method in my codebehind that looks like this:
public IQueryable<TestModel> GetForGrid()
{
return new List<TestModel>
{
new TestModel {FileName="File1", CreateDate=DateTime.Today.AddDays(-3), Type="Type1", UserName="user1"},
new TestModel {FileName="File2", CreateDate=DateTime.Today.AddDays(-2), Type="Type2", UserName="user2"},
new TestModel {FileName="File3", CreateDate=DateTime.Today.AddDays(-1), Type="Type3", UserName="user3"},
new TestModel {FileName="File4", CreateDate=DateTime.Today.AddDays(-2), Type="Type4", UserName="user4"},
new TestModel {FileName="File5", CreateDate=DateTime.Today.AddDays(-3), Type="Type5", UserName="user5"}
}.AsQueryable();
}
I can create a RadGrid with the following markup, and it filters data properly:
<telerik:RadGrid runat="server" ID="grid" ItemType="WebApplication1.AjaxGrid.TestModel"
SelectMethod="GetForGrid" AllowFilteringByColumn="true"
Width="100%">
</telerik:RadGrid>
-- I will update this answer as the discussion continues
Problem is, DateFiltercontrol is in updatepanel, solution is I have to set Postbacktrigger of updatepanel.
Telerik support is saying don't use AJAXControlToolkit and Telerik control in same project. but I have used AJAXControlToolkit in code and not able to remove it.
So applied solution is set control which cause postback as Postbacktrigger of updatepanel.

Categories

Resources