I ask myself if I could make the following statement simpler?
Can you help me out?
<Vorlesungsverzeichnis>
{
for $sws in distinct-values(doc('uni')//Vorlesung/SWS)
order by $sws
return
<Vorlesungen SWS="{$sws}">
{
for $v in doc('uni')//Vorlesung[SWS=$sws]
order by $v/Titel
return <Vorlesung VorlNr="{$v/#VorlNr}" Titel="{$v/Titel}"></Vorlesung>
}
</Vorlesungen>
}
</Vorlesungsverzeichnis>
The source XML is available here and you could also try out the query here.
Thanks for helping!
In XQuery 3.0 you can do the following:
<Vorlesungsverzeichnis>
{
for $v in doc('uni')//Vorlesung
order by $v/Titel
group by $sws := $v/SWS
return <Vorlesungen SWS="{$sws}">{$v}</Vorlesungen>
}
</Vorlesungsverzeichnis>
Related
For example
Json1:
{
"Data":"123",
"Data1":"345"
}
Jsonata1:
{
"Data":$.Data,
"Data1":$.Data1
}
Json2:
{
"Prod":"675",
"Prod2":"564"
}
Jsonata2:
{
"Prod":$.Data
}
How can I use like this if u observed my jsonata2 I call the jsonata1 feild data
I can't find any suggestions
Please help me resolve the issue
This is my search code please see then solution, thank you.
You have to use like this
$report_ex = Expenses::where(condition)->where(condition)->get();
or
$report_ex = Expenses::where(condition)->where(condition)->first();
If you are using
$report_ex = Expenses::where(condition)->where(condition)->first();
then you need to call
if(!empty($report_ex))
{
// your code
}
else
{
//your code
}
But if you are using
$report_ex = Expenses::where(condition)->where(condition)->get();
then you should use
if(count($report_ex) > 0)
{
// your code
}
else
{
// your code
}
since get function returns an empty object
I have the following code
val sortMethod = compareBy<Item> {
when (model.preferences.getSortMethod()) {
TITLE -> it.getTitle().toLowerCase(Locale.getDefault())
DATE -> it.getSortableDateString()
AUTHOR -> it.getAuthor().toLowerCase(Locale.getDefault())
DATE_ADDED -> it.getSortableDateAddedString()
}
}.thenBy { it.getTitle().toLowerCase(Locale.getDefault()) }
which i then use on Lists like so
myItems.sortedWith(sortMethod)
I like this solution and I think it's very elegant. However, i would like to add the ability to sort ascendingly/descendingly as well.
So I am asking how do I add a conditional .reverse() to my sortMethod? I am very reluctant to put a if condition on every one of my sort calls and would like to get it all done in the sortMethod logic
You can do it like this:
list.sortedWith(if (sortAscending) sortMethod else sortMethod.reversed())
I suggest removing Locale.getDefault() since toLowerCase() is equivalent to toLowerCase(Locale.getDefault()).
private fun List<Item>.sort() : List<Item>{
if (model.preferences.isSortedAscendingly()){
return this.sortedWith(sortMethod)
}
return this.sortedWith(sortMethod).reversed()
}
Decided my solution will be using the above extension function, but if anyone has a better way i would love to hear.
Use let()?
private fun List<Item>.sort() = sortedWith(sortMethod).let {
if (model.preferences.isSortedAscendingly())
it
else
it.reversed()
}
I'm sure that this is basic for someone that knows the answer. But I'm stuck. I've tried to look up the answer to no avail. How do I reference the fbRegistered value later in the code?
using (kvEntities ent = new kvEntities())
{
var user = from u in ent.kvUsers
where u.fbID == id
select new { u.fbID, u.fbRegistered};
if (user.fbRegistered) // < ???
{
// so how do I reference fbRegistered just above?
// this gives me an error.
}
}
Thanks!
The user contains collection. Use First or Single methods:
if (user.First().fbRegistered) ...
Suppose following codes:
IEnumerable<MyClass> MakeQuery()
{
var query = from m in session.Linq<MyClass>()
select m;
return query;
}
List<MyClass> m1()
{
return MakeQuery()
.Skip(10)
.Take(20)
.ToList<MyClass>();
}
List<MyClass> m2()
{
var query = from m in session.Linq<MyClass>()
select m;
return query
.Skip(10)
.Take(20)
.ToList<MyClass>();
}
Supposing all queries are same, it seems that in m1(), Skip and Take does not work. Indeed its like they do not exist all.
Why this happens and how can be fixed?
I'm using linq-to-nhibernate and this methods are used for paging. Thanks.
Why not use IQueryable for the MakeQuery() method?
IQueryable<MyClass> MakeQuery()
{
return session.Linq<MyClass>();
}
Not that the actual query makes a lot of sense. But I'll leave that to you.
But this is also the only difference between m1() and m2()