how to cast guid into string in odata, i have tried the $filter=(startswith(cast(CustomerID, 'Edm.String'),'1')) but it throws exception Unknown function 'cast'.
To perform a cast, the type shouldn't be in quotes. So it should be:
$filter=startswith(cast(CustomerID, Edm.String),'1')
(I also removed the extra brackets)
Related
I have nested comments. In order to fetch them from JSON, I have the following fromJson() function:
Comment.fromJson(Map<String, dynamic> json)
: id = json['id'],
...
children = json['children'] != null
? json['children'].map((c) => Comment.fromJson(c)).toList()
: null,
...
This checks if the current comment has any children comments, and if so, recursively parses them from JSON into a Comment. However when I run this, I get the following error:
[ERROR:flutter/shell/common/shell.cc(214)]
Dart Unhandled Exception:
type 'List<dynamic>' is not a subtype of type 'List<Comment>'
stack trace: #0 new Comment.fromJson (package:app/models/comment.dart:43:18)
Which points to the line where I assign children with children = json.... I'm new to dart, but I don't understand how mapping over a list, and returning a Comment doesn't let Dart infer the type of the list. How do I fix this? Adding as List<Comment> after toList() didn't work. If I add as Comment after Comment.fromJson(c), I get unnecessary cast.
Dart can't infer anything from json['children'].map(...).toList() because json['children'] is of type dynamic, and therefore it doesn't know what the .map call is going to resolve to at runtime.
At runtime, since .map is called without an explicit type, it ends up being a call to .map<dynamic>(...), and then .toList() returns List<dynamic>.
Try either:
Explicitly using .map<Comment>(...).
Casting json['children']: (json['children'] as List<Map<String, dynamic>>).map(...). It'd probably be a good idea to validate this anyway.
Good day,
I have problem. I want to simulate some errors in hacklang.
<?hh
namespace Exsys\HHVM;
class HHVMFacade{
private $vector = Vector {1,2,3};
public function echoProduct() : Vector<string>{
return $this->vector;
}
public function test(Vector<string> $vector) : void{
var_dump($vector);
}
}
Function echoProduct() returns Vector of strings. But private property $vector is Vector of integers. When I call echoFunction and returning value use as argument for function test(). I get
object(HH\Vector)#35357 (3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }
Why? I am expecting some error because types mismatch.
There's two things at play here:
Generics aren't reified, so the runtime has no information about them. This means the runtime is only checking that you're returning a Vector.
$this->vector itself isn't typed. This means the type checker (hh_client) treats it as a unknown type. Unknown types match against everything, so there's no problem returning an unknown type where a Vector<string> is expected.
This is to allow you to gradually type your code. Whenever a type isn't known, the type checker just assumes that the developer knows what's happening.
The first thing I'd do is change the file from partial mode to strict mode, which simply involves changing from <?hh to <?hh // strict. This causes the type checker to complain about any missing type information (as well as a couple of other things, like no superglobals and you can't call non-Hack code).
This produces the error:
test.hh:6:13,19: Please add a type hint (Naming[2001])
If you then type $vector as Vector<int> (private Vector<int> $vector), hh_client then produces:
test.hh:9:16,28: Invalid return type (Typing[4110])
test.hh:8:44,49: This is a string
test.hh:6:20,22: It is incompatible with an int
test.hh:8:44,49: Considering that this type argument is invariant with respect to Vector
Which is the error you expected. You can also get this error simply by adding the type to $vector, without switching to strict mode, though I prefer to write my Hack in the strongest mode that the code supports.
With more recent versions of HHVM, the type checker is called whenever Hack code is run (there's an INI flag to turn this off), so causing the type mismatch will also cause execution of the code to fail.
code is an integer, so it's declared as an Int in my subclass.swift file. The subclass is in the same format as the JSON, to enable saving the JSON directly to Realm.
I get this JSON:
...
"code": 301
...
And this is how I'm saving it:
realm.create(Student.self, value: jsonStudent, update: true)
But Realm throws this:
failed: caught "RLMException", "Invalid value '301' for property 'code'"
At first I thought the '301' might be getting parsed as a string, but that was not the case, calling 'dynamicType' on it in the debugger returns NSCFNumber, which is expected.
What's wrong?
NSJSONSerialization will convert {"code": 301} to an NSNumber of type q, which is integer. So the fact that you're getting an invalid property implies that the code property on your Realm model is of a different type (maybe Float or Double)?
Could you share your model definition here?
If your code property is actually Int or a variation thereof (Int32, Int64, etc.), this would imply there's a bug in Realm and I'd recommend that you open an issue at https://github.com/realm/realm-cocoa/issues.
I am trying to create a Predicate using a decimal data type but I get the following error:
Error retrieving data.A binary operator with incompatible types was detected.
Found operand types 'Edm.Decimal' and 'Edm.Double' for operator kind 'Equal'.
Error: A binary operator with incompatible types was detected. Found operand types
'Edm.Decimal' and 'Edm.Double' for operator kind 'Equal'.
Here is the code I am trying it with:
// engineSize equals 1.4 in this case.
predicate.create('engineLitreCapacity', '==', engineSize);
I'had the same issue. I found the mistery :)... I think that's somethings in naming convention related to metadata and the REST service controller sign: Eg:
Doesn't work
/*Breeze Controller Server Side*/
[HttpGet]
public IQueryable<Product> Items()
{
return _contextProvider.Context.Products;
}
/*Client*/
query = breeze.EntityQuery
.from("Items")
.where(Predicate.create('BasePrice', >', 1)
.orderBy(sortString)
.select(selectData)
.skip(skip)
.take(take)
.inlineCount();
It' works !!
/*Breeze Controller Server Side*/
[HttpGet]
public IQueryable<Product> Products()
{
return _contextProvider.Context.Products;
}
/*Client*/
query = breeze.EntityQuery
.from("Products")
.where(Predicate.create('BasePrice', >', 1)
.orderBy(sortString)
.select(selectData)
.skip(skip)
.take(take)
.inlineCount();
You need to parseFloat the engineSize:
predicate.create('engineLitreCapacity', '==', parseFloat(engineSize));
What is the datatype in metadata for the 'engineLitreCapacity' and does it match the datatype on your database for the same field? If not, how was your metadata initialized, via a FetchMetadata call or was it created by hand?
I was under impression that in F# the following two lines are supposed to give identical results:
let a = string v
let a = v.ToString()
It is implied that v is an object. It turns out that if v is a System.Guid the first line just throws an exception:
System.FormatException occurred
Message="Format String can be only \"D\", \"d\", \"N\", \"n\", \"P\", \"p\", \"B\" or \"b\"."
Source="mscorlib"
StackTrace:
at System.Guid.ToString(String format, IFormatProvider provider)
InnerException:
I can certainly deal with Guids separately, the question is what other objects will give me the same trouble? Should I avoid using the string operator at all?
In my case the object potentially can be anything
This is a bug that is (will be) fixed in the next release.
(In general, it should work; the bug is because System.Guid does not respond to the IFormattable "G" specifier, despite the fact that the docs for IFormattable say that all implementers must implement the "G" specifier. So it's actually kinda a bug in System.Guid, but the F# library will work around this bug in its 'string' operator in the next release.
In short, you can use this operator safely, except for Guid right now, but that will be fixed soon. In the meantime you can special-case Guid.)