'StartsWith' not working in Linq-To-EF - linq

I have implemented a Linq-to-EF expression using the sting comparison 'StartsWith', but it is behaving like the string comparison 'Contains'... my code is:
string ubi = '12';
return (from u in _dataContext.Notice
where u.UB.StartsWith(ubi)
select new AutoCompleteData { Value = u.UB }).Distinct().Take(50);
I would expect the data returned to be only values that start with '12'...but it returns values like '44412' and '312' as well as '1245' and '1299'.
Am I missing something ?

Related

Codeigniter 4 - how to get the first row and the last row of a result

I am trying to get the first row and the last row of a query result. I see from Ci4's docs, there are two methods to help, namley, getFirstRow([$type = 'object']) and getLastRow([$type = 'object']) but I am having difficulty using them. Here is my method so far:
function getLoginFailCount($login_fail_ip, $max_login_attempts = 3, $within_seconds = 320){
$builder = $this->builder('login_fail');
$builder->where('login_fail_ip', $login_fail_ip);
$builder->orderBy('login_fail_created_at','DESC');
$query = $builder->get(3);
print_r($query->getFirstRow($query));
}
I get an error at getFirstRow as follows;
Argument 1 passed to CodeIgniter\Database\BaseResult::getFirstRow() must be
of the type string, object given
How can I get getFirstRow() to work? Doesn't this doc definition say I need to pass it an object? Why does the error say it my be of type string
Well in the documentation for getFirstRow() it states that you can use
$row = $query->getFirstRow() // which will give you an object
OR
$row = $query->getFirstRow(‘array’) // which will give you an Array
So your error message, which states...
Argument 1 passed to CodeIgniter\Database\BaseResult::getFirstRow()
must be of the type string, object given
Would make you look and say to yourself, I had better go and read the documentation. So you can either pass in nothing, or a String 'array'.
So now can you see why
$query->getFirstRow($query))
does not make any sense! Why would you pass in the $query object as parameter.
You may have misread the documentation. I see you stated getFirstRow([$type = 'object'])
You might have got a little confused by that...
[$type = 'object'] means that the $type is defaulted to be the string 'object' so the returned type is an object by default with No Parameter being passed in.
If you want it to return an array, then you would specify the string 'array'. So then the $type parameter would be set to the string 'array' and return an array instead of an object.
Does that help!

Writing null values into parquet file with mapper

I am trying to do the following:
String x=null;
Group group = factory.newGroup()
.append("x", x);
context.write(null,group)
With the following scheme:
String writeSchema = "message example {\n" +
"optional binary x;\n" +
"}";<br>
But I get NullPointerException in the append line. Maybe I am missing something in the scheme?
Here the String object itself is null. While writing to the filesystem it tries to get the value of the object which is causing the NullPointerExeception.
String x =null;
System.out.println(x.toString()); // Will cause a NullPointerExeception
Similarly any function call to the object will cause the same.
Try using String x ="null" instead

Evaluate String value in jmeter

I want to evaluate the value of SEATID.
Find my code below.
String res2[0] = "40B";
vars.put("SEAT_ID",res2[0]);
When i am trying the get the value of SEATID in a string i am not getting the actual value of SEATID.
String otherSampler = vars.get("{"seatCode":"${SEAT_ID}");
Output is coming as : {"seatCode":"${SEAT_ID}
Expected output : {"seatCode":"40B"}
I am wring the code in Beanshell pre processor. Please help.
You need to use vars.get on SEAT_ID
String otherSampler = "{\"seatCode\":\"" + vars.get("SEAT_ID") + "\"}"
Your code is wrong. Try using this for declaring SEAT_ID variable:
vars.put("SEAT_ID","{\"seatCode\":\"" + res2[0] + "\"}");
Then you could use:
String otherSampler = vars.get(SEAT_ID);
To get:
{"seatCode":"40B"}

What does "read_strt" meaning here?

What does this vbscript code mean?
<%=read_strt(objRS, "ccnumber", "")%>
I want to know whats the meaning or used of read_strt on the code?
Any ideas?
The statement writes the return value of a call to the function "read_strt" to the HTML output stream. The function seems to read the value of a field/column in the current row of a database query (recordset), convert its type to String and/or test it against 'bad' (e.g. Null) values; in that case the default value ("", empty string) is returned.

What is the MinValue of Byte[] in C#

We represent MinValue of DateTime as DateTime.MinValue but how is it represented for Byte[]?
When I gave the below,
DALImage.TwinImage = Convert.IsDBNull(reader["TwinImage"]) ?
Byte[].MinValue :
(Byte[])reader["TwinImage"];
I get the error as 'byte' is a type but use like a variable
syntax error value expected (in '[]' part of Byte[])
Please Help as am a newbie to C# programming
An array of bytes doesn't have a minimum value - it doesn't make sense as a concept. It's like asking "What's the minimum value of a shopping list".
I think what you are trying to do is get an empty Byte array.
DALImage.TwinImage = Convert.IsDBNull(reader["TwinImage"]) ?
new Byte[0] :
(Byte[])reader["TwinImage"];
EDIT:
Your comment suggests that what you actually want is a byte array with 1 element in it, where that element is the minimum value of a byte.
That would be the following code:
DALImage.TwinImage = Convert.IsDBNull(reader["TwinImage"]) ?
new Byte[1] { Byte.MinValue } :
(Byte[])reader["TwinImage"];
However, this could also be written using default, which is probably semantically cleaner.
DALImage.TwinImage = Convert.IsDBNull(reader["TwinImage"]) ?
new Byte[1] { default(Byte) } :
(Byte[])reader["TwinImage"];

Resources