Does anyone know why Take() isn't working here - nhibernate

i have the following code using Nhibernate.Linq
var apps = Session.Linq<History>().OrderByDescending(r => r.LastUpdated).Take(50);
Console.Write(apps.Count());
the count returns 1000 (NOT 50 which is what i would have expected)
any ideas why the .Take() is not working?

It looks like a bug in the Linq provider (you are using the old one, I tried the new one too and it still doesn't work).
You should open an issue in http://jira.nhforge.org/
As a workaround, use .ToList() in the assignment to apps.

Related

Minecraft Spigot I cannot get String from Component

Hello Support I can't get the String from a Component. I did this with 2 ways with bad results.
TextComponent textComponent = (TextComponent) item.displayname;
return textComponent.content();
The result of this is a error with Casting
and
return PlainTextComponentSerializer.plainText().serialize(item.displayname);
The result of this is Literaly "chat.square_brackets" which is weird.
Please Help. Thanks
I also was having trouble with this. Here's what I found to work for me. Full disclosure that I'm developing my plugin on the PaperMC 1.16 fork and not Spigot. So it's possible that this may not work for you, either because it isn't a part of Spigot or because you are working in a version that this feature is not a part of.
To start, I would first check to make sure that we are both on the same page. For me, the component objects being used are from a package called net.kyori.adventure.text if yours are not provided by this package I don't know that this solution will work for you.
Also as mentioned by others, accessing the displayName directly on the ItemStack isn't going to give the desired results. Instead, you need to do itemStack.getItemMeta().displayName(). This method should then return a net.kyori.adventure.text.Component; once you have the component you need to serialize it using one of the serializers from the previously mentioned package.
That will look something like this:
Component itemDisplayName = itemStack.getItemMeta().displayName()
PlainComponentSerializer plainSerializer = PlainComponentSerializer.plain();
String itemName = plainSerializer.serialize(itemDisplayName);
The package that the serializer is from is: net.kyori.adventure.text.serializer.plain.PlainComponentSerializer
I don't understand how you can access to the displayname field in ItemStack in the Spigot API.
You should use ItemMeta to manage display name. To get the item meta, you should use ItemStack#getItemMeta.
Don't forget to check if the item as a meta with hasItemMeta. You can also use hasDisplayName to be sure that the display name is valid.

mongodb differences between clients

I'm very confused and I can't seem to find any explanations on the web. windowStart is a ISODate in my documents.
When using the mongodb-java-driver (via the mongoTemplate in Spring) the following works fine...
{windowStart : {$lt : new Date()}}
When I use MongoDb Compass GUI and type the above in the Filter it is marked as not valid. If I change it to...
{windowStart : {$lt : new Date('2018-10-01')}}
...then it is marked as valid and works
Another example...
{windowStart : {$gt : new Date(new Date('2018-10-01').getTime()+1000*60*60*24*64)}}
Does not work in mongodb-java-driver (via the mongoTemplate in Spring).
Does work in MongoDb Compass GUI
So I just can't work out what I can and cannot do. There is something I'm missing about how the client drivers work and the differences? I see lots of examples on the web for searching date ranges etc yet most don't work for me, so again I'm wondering what client they have been written for
In the below script, you will get data between the given date
{windowStart:{$gte:ISODate('2022-12-28'),$lte:ISODate('2022-12-29')}}

DataTable or dataTable?

On the DataTables website there are a number of examples given for functions on a table. In some they use:
table = $('#example').dataTable();
in others...
table = $('#example').DataTable();
It took me a while to notice that some functions work only on the former, while others only on the later. This is really confusing and I haven't been able to find any clarification on the difference between the two.
Currently I am at a standstill as I require two functions that only work on one or the other:
table.fnAdjustColumnSizing
and
table.column(x).search(this.value).draw();
Anyone have an idea for how to build the table so both of the above can work?
DataTable (uppercase first letter) indicates a method from the new api. The latest versions of DataTables still support the old methods, but you should use the new api when possible.
http://datatables.net/manual/api#Accessing-the-API
This is probably what you need for your question:
table.columns.adjust().draw();
https://datatables.net/reference/api/columns.adjust()
See the upgrade facts -> http://www.datatables.net/upgrade/1.10-faqs
Q. I get an error message when trying to access one of the old fn*
style API methods A. This is the inverse of the above issue.
DataTables 1.9 attached a number of functions (all starting with fn)
to the jQuery object. The old API is still available, but you must use
$().dataTable() to access the jQuery object.
Simply use
$(window).bind('resize', function () {
$('#example').dataTable().fnAdjustColumnSizing();
});
see demo -> http://jsfiddle.net/uL5x4dg1/ if you want to use the old API functions along with the new DataTable() API. dataTable() does not reinitialise the table, it just returns the oldstyle jQuery object.

How to delete a db row in LINQPAD

Total NOOB question. I have been using the new linqpad for about 20 minutes now. Great!
But now i want to delete a row in the db. I am using a EF5.0 connection. I cant seem to find anything in the help files or on the net. The only thing I can find is DeleteOnSubmit which doesnt work with EF (as far as I can see). I have also tried DeleteObject which doesnt work either. This is what I have tried.
var co = Companies.First();
co.Dump();
Companies.DeleteObject(co);
This is old... and I don't know if/when this was added (probably in response to this exact scenario)… but you can accomplish this (in your given example) as follows:
//test the following line to ensure the context doesn't complain about the .First() reference
Companies.DeleteOnSubmit(Companies.First());
Companies.Context.SubmitChanges();
You need to SaveChanges on your context (Companies) for your row to be deleted.
Companies.SaveChanges();

Lucene query parser not parse field as expected

I want to parse a simple query using lucene (3.0.3):
title:(+return +"pink panther")
Just like in the documentation example.
The expected result is:
+title:return +title:"pink panther"
But instead i get:
+title:return +title:"itle return pink panther"
The code is very simple (c#):
Query query =
new QueryParser(
Lucene.Net.Util.Version.LUCENE_30,
"content",
new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30))
.Parse("title:(+return +\"pink panther\")");
I'm unable to reproduce this. Does this still occur for you?
I'm thinking that it may be some display artifacts from the output window. Is this from the Immediate Window, the Watch Window or a call to Console.WriteLine?
Sorry for the trouble, the issue was a custom-modified Lucene.Net assembly...