Grouping and Paging with DomainCollectionView - c#

I'm trying to get grouping and paging (in a datagrid) to work simultaneously in RIA Services. I already have a pretty elaborate UserControl that is based on the excellent DomainCollectionView. However, I've had trouble making the grouping work.
I added this line to the sample:
this.CollectionView.GroupDescriptions.Add(new PropertyGroupDescription("Int32"));
Note about the sample: I changed how Int32 is being assigned as key % 2, so there should be
two resulting groups, which should have hundreds of items per group. The paging is set to 10 items. No grouping is applied at the query level.
So in this case, I would expect the grouping header to show the total number of items, however, it'll just 'Group 0', as having an item count of 10, which is clearly incorrect. It is only showing the item counts in the first page.
Question
Did any make grouping and paging work together with or without DomainCollectionView?
For proper context refer to the article regarding DomainCollectionView and the sample posted for it.

Kyle McClellan of Microsoft replied to a personal email regarding this question and provided the detailed explanation below.
In summary, grouping and paging won't work together well - you certainly won't get a fully featured grouping experience in the DataGrid.
For me the solution will be to remove paging when grouping is present.
On Wed, Jun 6, 2012 at 7:51 PM, Kyle McClellan
wrote: Ah, now I understand what you were expecting. There are two
(competing?) things at play here. First, the client technology knows
nothing about the server. It only sees data that exists locally.
Because of this, the controls, etc. will report that there’s only a
single group and it only contains a page’s worth of data. Second, the
server technology can see the all the data but has only been asked to
return a single page. It sorts and slices the data appropriately and
then returns it. It could determine the number of groups and the size
of each, but there’s no way to communicate it back to the client.
What you’re seeing is the view functioning as designed. It will show
you all the items in group 0 before all the items in group 1. At some
point in the middle you will see two groups on a page, but otherwise
the results will all be in the same group.

Related

Elasticsearch NEST Indeces and Indexing

my following problem is, that I have a List of Items and want to index those with elasticsearch. I have a running elasticsearch instance, and this instance has an index called "default".
So I'm running following code:
var items = GetAListOfItem();
var response = Client.IndexMany(items);
I also tried it with Client.IndexManyAsync(items). But that didn't do anything.
Only 1 Item of this List gets indexed. Nothing more. I think its the last item, which got indexed.
I thought it could be a thing with IEnumerable and multiple enumerations, but i parsed it as a List<Item>.
Another Question would be about the best practice with Elasticsearch. Is it common to use a Index per Model. So if I'm gathering data from for example Exchange and another system, I would do 2 indeces?
ExchangeIndex
OtherSystemIndex
Thank you for your help.
Update: I saw that my Client.Index does all those calls succesful, but all those objects got the same ID from NEST. Normally she had to increment by herself, isnt it?
Update 2: I fixed the Indexing Problem. I had setup an empty ID-Field.
But still have the question mit best practive about Elasticsearch.
If you are uploading all the data with the same id, it will not increment the id, that will update the record with that id and you will have only one record, so you can upload the data without an id or give wherever unique id to identified the records.
The other common problem is that your records have not the same mapping that you give for the index.
About the other question, in the indexes, you store the information that is relevant for you, even if that have content from many models, the only thing that you have to avoid is mix information, if you have an index about server logs dont mix it with user activities for example.

techique to avoid multiple loops in different areas of same page using same model?

MVC view have strongly typed List as model. As per page template design, to display data from Model I need to do multiple loops. Situation is I can't put every thing in a single loops because some containing tags (for example div, section and tables) are to be displayed just once.
I m looping in top of page, multiple loops in body and in footer. Model is search result and in itself would be heavy and dynamic, on average it will have approximately 250 records. 250 records and looping it for 10 to 15 times is much resource consumption.
I m sure this is not a new challenge but wondering how it is dealt. Can you please guide me what can be done to make situation better. Currently it is server side model binding.
Edit: Adding a snap short of my template design, please note it is just a part of design there are many other parts as well.
Looping 250 records 10 to 15 times is not a resource problem.
The list doesn't contain the actual records, it only contains references to the records, so getting the records from the list is not a resource heavy operation at all.
If you actually need data from the list in 10 to 15 places in the page, then what you have is fine.
Due to design I have to do multiple loops I was trying to avoid it. If some one has same issue would be good to use some JS binding library.

Find exact position then insert or add then sort? Which is better?

We have a big List of >1000 items with big classes (of the same type).
The list is inserted or deleted very frequent. About 10 or 20, 30 items inserted at a time. With each item, I find exact position to insert using quick search algorithm.
But I wonder if I add every items to the end of the list then do the sort using List.Sort (I believe that MS use quick sort algorithm) then it will be better: consume less CPU like current?
I am using C#, .Net Framework 2.0.
There's rarely a general answer to questions like these. It depends very heavily on your scenario. But here's an intermediate suggestion between the two choices you bring up:
Sort the list of items to be inserted (this requires sorting 10 - 30 items based on your description). Then, insert these in order. Note that once you find the position to insert the first item, the position to insert the second item must be strictly after that location (and so on, for each subsequent item), so you don't need to search starting from the beginning again. The list being inserted into only needs to be searched through in this case as it would maintain its ordering after each insertion.

How can I properly present and write a checkboxlist to a db? (Theory/Logic help)

Please note that the database design I have now is fully in sandbox mode. Nothing is finalized. Everything (again this is in sandbox mode) is in one single table. Also, I'm in now way looking for coding help. I'm looking for the right theoretical/logical approach to this puzzle so I can go in and play with the coding myself. I learn better that way. If I need coding help, I'll come back here for further assistance.
I'm in the process of creating the first of a few CheckBoxList for a manually created form submittal. I've been looking over multiple ways to not only create said CheckBoxList but to enter it into the database. However, the challenge I'm facing (mainly because I haven't encountered this scenario before and I'd like to learn this) is that I not only need to worry about entering the items correctly in the database but I will eventually need to produce a report or make a printable form from these entries.
Let's say I have an order form for a specific type of Barbeque grill and I will need to send this form out to distriution centers across the nation. The distribution centers will need to pull said barbecues if they are highlighted on the form.
Here's what the CheckBoxList for the distibution centers will look like:
All
Dallas
Miami
Los Angeles
Seattle
New York
Chicago
Phoenix
Montreal
If the specific city (or all the cities) are checked, then the distribution center will pull the barbecue grill for shipment.
The added part is that I want to:
be able to create a grid view from this database for reporting to note which distribution center got orders for barbecues and
be able to create reports to tell what distribution center sent out barbecue orders in a given month (among other reporting).
Here's what I'm playing around with right now.
In my aspx page I have a checkboxlist programmed with all the distribution centers entered as a listitem as well as an option for 'ALL' (of the distribution centers).
I also created a dedicated column in this table that holds all the information in the listitem and programmed a sqldataconnection to this table to play with the programmability of leveraging the database for this purpose.
When it comes to writing the selections to the database, I originally created a column for each destination city including the 'All' option. I was toying around with just putting the selections into one single column but with some of the information I've been reading today about Database Normalization, the former options seems to be a better one than the latter. Is this correct practice for situations such as this especially if I need to think about reporting? Do I put the CheckBoxList data in one cell in a specific column? Do I create seprate columns for each distribution center? Am I even on the right track here?
Depending on the amount of cities that you want to store, I've used bitwise operators to store small amounts of data. Effectively, it would store it in the table like this:
CityID Location
2 Dallas
4 Miami
8 New York
16 Chicago
32 Montreal
and keep going in base 2 for additional cities.
When your user selects multiple cities for the order, the value that gets inserted into the database for cities is a bitwise OR calculation. So if they select Dallas, New York, and Chicago, you would be doing the following:
2 OR 8 OR 16
Which would equal 26
Now, you can use bitwise AND on the resulting value. So if checking for Miami the following is the evaluation:
26 AND 4 = 0
which indicates that Miami was not selected. Any value that was selected in the evaluation, it would return its ID like this:
26 AND 8 = 8
Again, I've only used this for small subsets of data, and to make the data storage as compact as possible. Computationally, it may be a trifle more expensive that some other methods, but I'm not 100% certain.
Note: This might not be the best approaches but I have seen them used.
1) Having one column of comma-delimited string
This should work well if the options don't have IDs in the database (having a separate referenced table)
You will need to loop through the checkbox list, obtained the selected options and concatenate them with String.Join()
You will need to split the string upon receiving it from the db and use it to check the checkboxes if there text is found in the resulting array
Problem: You might need a split function in the DB that converts the comma-separated string into rows. There split function implementation on the web/stackoverflow
2) You can have a separate table for the locations e.g. xxxxtable_location where the FK to the main table is referenced. This will be a one-many table
ParentID, Location
1 Dallas
2 Miami
2 New York
2 Chicago
3 Miami

C# MongoDB, remove top 10 from sorted collection

I have a collection with 1000 items. I want to sort them per date (SaveDateUtc field) and remove the top 10 of them, so I'm left with the 990 newest items in my collection.
I could do a Find and then a Remove, no problem, but it'd be much better if I could do this with just a Remove call. But I can't find a way to sort and set top 10 through the query.
So my question is, can I do this in just one call?
(I'm using the C# driver)
Actually there was similar question: MongoDB find and remove - the fastest way
But unfortunately findAndUpdate cannot be restricted by records number. So my propositions to you:
You may introduce some surrogate field so you could use it as field in query
You may write you own java-script server-side function that will do this operation on server side. Benefits - operation is done on server, it is atomic. Pitfall - it is not works with sharded tables.

Categories

Resources