How to keep dirty data sorted in a Lightswitch Grid - queue

I have an entity that has an "Order" column.
I have a grid onscreen bound to a collection of said entities.
Entity items should move up and down the grid, simply by changing the value of "Order" as the query that populates the collection is sorted by "Order".
The logic of this works perfectly, however I cannot get the grid to sort it's rows programmatically, neither does it do it automatically save for when the data initially loads.

Have you tried to write code in TestQuery_PreprocessQuery like:
partial void TestQuery_PreprocessQuery(ref IQueryable<Label> query)
{
query = query.OrderBy(c => c.Order);
}
Also there has been some considerations about calculated fields, relational fields and resorting. you can take a look at this Lightswitch grid sort problem

Related

How to correctly handle simplified model in Fluent/Vapor?

Let's assume, I have a User model and this model contains products children (one to many relation).
In some situations, in my iOS app, I need only to display list with all users so I don't need to query my database about products.
How to preform, in the easiest way, fetching users without its children in Fluent?
Do I need to create a separate model that doesn't contain products?
func getAllUsersHandler(_ request: Request) -> EventLoopFuture<[User]> {
User.query(on: request.db).all()
}
The default situation is that a query on the User model will not include any Children fields in the result. To include them, you need .with(\.$products) in the query.
You can limit the fields returned by modifying your query as in the example:
User.query(on: request.db).field(\.$name).field(\.$email).all()
This only brings those fields into the model and leaves unwanted fields in an uninitialised state. See here for more information.

CoreData shared entity properties

I'm new to Swift/CoreData and SQl databases. I have a CoreDatabase with over 7000 items. I want to create an entity (or any other way) to store how often a certain entry in the DB has been used. I need this in order to create a weighted sorting algorithm that suggests certain entries.
The catch is that I do not want to store this on the entries themselves, they need to remain generic in order for me to be able to update them every now and again via my own Node server. So all users have the same DB. Whenever the user picks one of the items it's counter increments by one. Whenever I query an item the frequency should come with it so I can perform a sorting algorithm on it.
I've been reading up on articles, it seems like this can be done, but none so far have been really useful. I've also looked a SQLite articles on this but haven't found what I was looking for.
I'm thinking something along these lines:
FrequencyList { Item_1 { ...7000 items....
item_1_freq : 0, ------------> frequency : 0,
item_2_freq : 12, name: "lala"
item_3_freq : 3 ...
... };
...
7000?!?!
};
Or would a separate 'meta' entity in a one-to-one relationship with it's respective Item be a good solution?
How can I tackle this?
In Core Data it would probably be better like this:
Put the selection in an entity with a count property, and have a relationship between the selection and the item. The Selection --> Item relationship could be to-one or to-many depending on your needs; I have it as to-many here but that might not be best in your case.
If you want to get the number of selections for an Item, use the value of selection.count. Update selection.count when a selection occurs.

EntityFramework 5 - Change Initial Order of Items in Collection (NavigationProperty)

is it possible to change the item's order in a collection that is a navigationProperty?
sample:
A Entity "Order" has many "Item" Entities. One to Many Relation.
i want that all items of an order a sorted by the name. How could i do that without a query on the DbSet? I want that the items are sorted after i load them into the context.
Is this possible to manipulate the generated SQL Query from the EF to add a ORDER BY ?
Thx for the help!
No. You'll have to do that when you process the items in any way, e.g. for display.

Entity Framework: Exclude columns from the selection in Entity Framework?

I want to have an ObjectQuery that returns tracked entities (not static data), but I don't want it to load all the columns, I want some columns to load as null, I don't want to use select, since this will return an IEnumerable of the values, not tracked objects.
Is there a way to do it?
If yes, how do I then complete reloading those columns on demand?
Have you tried creating a view and then mapping the view?
By creating a view you can select the columns that you really want and only those will show up on the Entity Model.
I think the only way is to create new entity type which will not contain columns you don't need. You will map this entity type to the same table. On demand (lazy) loading works only for navigation properties.
Edit:
My previous idea doesn't work but in some special cases you can use idea from this article. Instead of modeling single entity from single table you will model multiple entities related with 1:1 relations. Entities will not overlap in properties (except the primary key) as my previous idea assumed because it doesn't work. You will than have main entity with fields you want to load immediately and related entities which will be lazy loaded when needed.

ASP.NET Dynamic Data : How to Specify Sort Order of Items in Dropdown List

I am using ASP.NET dynamic data for the data adminstration tasks for a Silverlight app that I built. It saved a ton of time not having to write all of the admin screens you typically have to create for end users to manage the data.
One thing I cannot figure out how to sort the items in the drop downs that appear on the screens - either the filter dropdowns on the list views or on the data entry screens.
Do I specify that somewhere in the EDM partial classes or in the ASP.NET DD field templates? or somewhere else?
All I need to do is sort alphabetically by the display value- they appear to be in random order.
thanks
Michael
Use the DisplayColumn Attribute in the System.ComponentModel.DataAnnotations Namespace.
http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.displaycolumnattribute.aspx
ex:
[DisplayColumn("LastName", "LastName")]
public partial class Employee
{
}
The answer to your question can be found here, about halfway down the page:
http://csharpbits.notaclue.net/2008/08/dynamic-data-and-field-templates-second.html
In the Cascase.ascx.cd FilterControl and Cascade_Edit.ascx.cs FieldTemplate you will find a method GetChildListFilteredByParent. This returns the values for the filtered DropDownList, but as you will see this list is an unordered list. To add sorting to this list we need to add a Linq OrderBy clause.