lambda contains in array - asp.net

My array A may be returns array of age likes
int [] A = {11,12,13} or
int [] A = {14,15} or
int [] A = {11,14}
My Person table has column likes
ID Name Age
---------------------
1 John 12
2 Michael 15
3 Tom 13
4 Owen 14
How can I get row from this table depend on my array's values using lambda ?
myASPGridView.DataSource = DBContext.Persons.Where(.....);

It should be something like that:
int [] A = {11,12,13};
myASPGridView.DataSource = DBContext.Persons.Where(p => A.Contains(p.Age));

Do you want this?
x => A.Contains(x.Age)
x denotes the input (in this case, your database row) and the function returns true where the array A contains x.Age.

Related

Count in xquery

I'm trying to solve this question but this code give me the result without counting it. What i mean it's that i need it to be a 13 but the result its divided by rows with a value of 1.
1
1
1
1
1
1
1
1
1
1
1
1
1
This is the question and this is what i have done.
List the number of countries that have a border (element ) in a country that has a Buddhist religion (element , value "Buddhist"). The correct query has to return the value 13.
for $var in /mondial/country
let $religion:=/mondial/country[religions="Buddhist"]/data(#id)
where $var /border/#country=$religion
return data (count($var/name)
This should get you there. I changed variable names to make things a bit more readable:
let $country := mondial/country
let $buddhist := $country[religions[./text()="Buddhist"]]/#id
return count($country[.//border[#country=$buddhist]])
Output:
13
Rather than returning the count for each item as you iterate, return each selected item and assign it to a variable, then you can get a count of the items of the sequence assigned to that variable:
let $names :=
for $var in /mondial/country
let $religion:= /mondial/country[religions="Buddhist"]/data(#id)
where $var/border/#country=$religion
return $var/name
return count($names)
You could also do this in a single XPath statement:
count(/mondial/country[border/#country=/mondial/country[religions="Buddhist"]/data(#id)])

Can I use tabular parameters in Kusto user-defined functions

Basically I'd like to pass in a set of field values to a function so I can use in/!in operators. I'd prefer to be able to use the result of a previous query rather than having to construct a set manually.
As in:
let today = exception | where EventInfo_Time > ago(1d) | project exceptionMessage;
MyAnalyzeFunction(today)
What is then the signature of MyAnalyzeFunction?
See: https://learn.microsoft.com/en-us/azure/kusto/query/functions/user-defined-functions
For instance, the following will return a table with a single column (y) with the values 2 and 3:
let someTable = range x from 2 to 10 step 1
;
let F = (T:(x:long))
{
range y from 1 to 3 step 1
| where y in (T)
}
;
F(someTable)

Describing a String type in Ada

I have a type similar to:
type ID is new String (1 .. 7);
-- Example: 123-456
How can I specify that format in code, either with Ada or SPARK?
I was thinking about Static_Predicate, but the condition that the string must start with 3 positive integers followed by a dash followed by another set of 3 positive integers can't be described with a Static_Predicate expression.
You have to use a Dynamic_Predicate for this:
type ID is new String (1 .. 7)
with Dynamic_Predicate => (for all I in ID'Range =>
(case I is
when 1 .. 3 | 5 .. 7 => ID (I) in '0' .. '9',
when 4 => ID (I) in '-'));
I'm using this quite a bit myself, but I mostly make the types subtypes of String instead of actual new types.

While querying with linq , Max function retrieves upto '9' if more than 9 values in the list

While querying with linq, Max function retrieves up to '9' if more than 9 values in the list
MaxItemNumber = ItemDetailList.Max(e => e.ItemNumber);
Here ItemDetailList contains more than 10 items, but MaxItemNumber is 9, this is not taking into account values above 9.
I need to get max of item number. Please help
ItemNumber is string
Try this:-
int temp = 0;
MaxItemNumber = ItemDetailList.Max(e => int.TryParse(x.ItemNumber,out temp) ? temp : 0);
Although, if you wanna store int then why your type is String?

List<int> except(AnotherList<int>) not return correct results

here is my data:
OldAnswers :
2
NewAnswers :
2
3
4
int Diffcount = OldCountryAnswers.Except(NewCountryAnswers).Count();
Diffcount is coming out as 0.
Is this right behavior of 'Except' ?
I need difference count between two List<int>.
int Diffcount = NewCountryAnswers.Except(OldCountryAnswers).Count();
might be what you are looking for, this should give you a count of 2.

Resources