Change XamGrid column header dynamically - mvvm

I am having user group returning from wcf service and using view model binding it to xamgrid in view, Since grid is having auto generate column is true, grid column headers same as propertyname(without space).
I want to change the column header.

There are couple of ways to do it. If you still want to do auto generate columns true then you can subscribe to AutoGeneratingColumn event in the grid and listen to each column and set the column header to the name you want. The other option not sure it will work in your case, is in the model you can decorate each member using component model annotation http://msdn.microsoft.com/en-us/library/cc490428(v=vs.95).aspx or Using DataAnnotations (DisplayColumn) in WCF RIA Services

Related

Liferay Service Builder - is there a recommended way to describe a self reference relation in service.xml?

I want to describe a self reference relation in a Liferay entity. Is there a recommended way to do this ?
I want to do this in order to describe a hierarchy.
At the moment, I just added a new column which I called "parentId" and I will save there the ID of the row that will be the parent of this one. If I use the "Diagram view", from within eclipse, if I draw a self reference relationship it adds a new row that duplicated the name of the ID: for example, suppose I want to describe an employee hierarchy - I have an Employee entity on which I add the default fields; one of these fields is the employeeId field which will be also the primary key. Now, if I draw a self reference relationship, the IDE will add another field entry that will be named the same way (eg. employeeId)
There is no official recommended way to do it, as you will have to add your own logic in your code to handle it.
In case you want to follow the convention used in Liferay code, Liferay code usually represents the hierarchy using a column called parent<primaryKey> and sometimes an auxiliary column called treePath to store the hierarchy path of the element, see:
https://github.com/search?q=repo%3Aliferay%2Fliferay-portal+filename%3Aservice.xml+parent&type=Code
https://github.com/search?q=repo%3Aliferay%2Fliferay-portal+filename%3Aservice.xml+treePath&type=Code
About the treePath column, service builder will add to the java class some methods (buildTreePath and updateTreePath) that will help to populate it, see the service builder templates: https://github.com/liferay/liferay-portal/blob/11e6081f96abb6bf299369519434c1eafa0658e3/modules/util/portal-tools-service-builder/src/main/resources/com/liferay/portal/tools/service/builder/dependencies/extended_model_base_impl.ftl#L65-L115
This column makes easier to get all the parent elements of the hierarchy, just split it by the / char and you will get all the primary keys of the ancestors.

Multiple Table Versions

I'm looking for a little "magic"
We have multiple applications written using entity framework. We need to update the scheme of a couple of columns - basically increasing the size of some account numbers columns. In our situation, we host the application for other customers and do not wish to increase the size of their account numbers but would like to have a single entity framework implementation for both.
The logic is the same with both tables - only the field length changes. This is a very large code base and refactoring, rewriting etc. the ideal solution.
Is there a way to specify in a config file what the field length is so it can be built at runtime?
Application
Table
Customer Name (256)
Account NUmber (10)
Same Application
Table
Customer Name (256)
Account Number (18)
You can write your own custom validation attribute with EF like in these examples: Custom validation attribute that compares the value of my property with another property's value in my model class
Pass variable data to ValidationAttribute
You can read your CustomerName property value, and based on the data you can validate your AccountNumber property. And in this custom validator you can read your config file.

Combine fields from two tables into one autocompletebox

I have two tables "Services and Projects". Both tables have a "Name" field. I would like to take both fields from both the tables and put them into a single autocompletebox in one of my screens. I searched around and found different methods of doing this but not in LightSwitch. Any ideas?
If I understand your requirement correctly, you want the Name property from both Services and Projects to appear in a single textbox? If this is the case, my approach would be as follows:
Use a view on the data source to union the Projects and Services data sources
Add that view to your data model (on a new data connection)
Define Name as the summary property for the new view-based entity.
Add the view to your screen as a separate query
Add the view data object to your screen as an auto-complete box.
WARNING: You'll also need code-behind to identify whether the value selected is a Project or a Service and to apply this value to the relevant field in your linked entity.

Foreign entity in form into different kind of input

I have two entities: product and category (Symfony 2.3).
I want to create a form in which an user can choose a product by first selecting the category. A user selects the category by clicking on image, then I want to set the image's value into a hidden input, but I don't see how can I change a foreign entity choice list to a hidden input (http://symfony.com/doc/current/reference/forms/types/entity.html).
How can I accomplish this? (how to change form input to hidden)
If I set cascade validation to true, will it for example check if a category really exist. (To prevent putting products with non-existing category from malicious users) ?
Part 1
To do this you need to use a data transformer to do two things:
transform an entity into an identifier that is either a string or integer so a form can render it as a hidden field.
transform the string or integer identifier into the entity when the form is submitted so that the parent entity can be saved with the correct relationship
The symfony docs I linked to above (here too) actually walk though an entire example of using a data transformer with a form.
As a shameless plug (because I believe it is helpful) I have written a little tutorial on using a data transformer for a hidden field with an entity id: http://lrotherfield.com/blog/symfony2-forms-entity-as-hidden-field/
Part 2
If you are using the data transformer then you don't need to worry about malicious users. The data transformer will fail because it will not be able to reverse transform the category from the fake id. In my tutorial the transformer will throw a Symfony\Component\Form\Exception\TransformationFailedException exception.
You can also write a validator (potentially using a call back) if you wanted that checks that the submitted category is real if you want an error to show in the form. Doctrine wont allow you to persist a fake category relationship as the foreign key constraint will fail.

Supporting default column values in custom Entity Framework provider

I'm working on a custom entity framework provider and I need to add support for default column values for this provider. When the user uses the entity framework wizard and selects a table that includes columns with default values, those default values are not being populated into the entity designer.
I'm a little lost on where exactly this population should take place. I believe the appropriate place would be in the GetEdmType method override of DbXmlEnabledProviderManifest but I just don't see how to set the default value, if this is the correct place.
Anybody has experience writing EF providers that support default values for table columns? How do you implement this?
I am a bit late to the party but DbXmlEnabledProviderManifest is not the right place for adding default values. The provider manifest describes capabilities of the database engine itself and is specific (and general) to this database engine and not to a given database and/or table. The default value in the provider manifest tells EF what value to use for the given column property if one is not provided by the user (e.g. if the user user does not specify scale or precision for a decimal column the value from provider manifest will be used for scale and/or precision used for this column).
If you want just to insert a default value for a property the easiest way is to set the property that corresponds to the column on your entity to this value in the constructor. This way the user can always set it to a different value but if s/he does not the default value will be sent to the database. For some corner case scenarios where some of the columns in the database do not have corresponding properties on entities you can use DefaultValue attribute on the Property element in SSDL which will be inserted to the database when you add a row. This is especially useful if those properties are not nullable since without telling EF what value should be inserted EF would try inserting null which would obviously fail for non-nullable columns.