EMF-Edit: visualizing the object referencing an object? - code-generation

I created a EMF ecore model that could look like this:
The model contains a list of Family
The model contains a list of VisitedCountry
A Family contains a list of Individual
A VisitedCountry contains a list of references to some Individuals
after the plugins EMF-Edit and EMF-Editor have been generated and when I run the generated GUI: when I click an Indvidual, is there a way to display a table listing all his VisitedCountry ?

To easily do that, you could add a non-containment reference from Individual to VisitedCountry, which must be an opposite reference (EOpposite) to the reference you defined from VisitedCountry to Individual.
Doing that, you could check when selecting an Individual when editing your model with the generated model editor, you can access their VisitedCountry in the Properties View. In general defining EOpposite references beetween classes is always useful for other puposes, since you have bidirectional navigation between both classes.

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.

DBIx::Class Find or Create objects

I'm using DBIx::Class to model the following:
A Recipe with many Tags. The Tag is shared with other Recipe objects.
While creating a Recipe object I want to create a set of Tag objects and associate them with the newly created Recipe object. (The user enters a list of tags and I only have the name of the tag to go with)
For the Tags I could iterate over the list and find one that matches the user entered name or create a new object manually.
I couldn't find a documented findOrCreate type method in DBIx::Class. Any suggestions ?
If you have a key on the name you can use find_or_create.

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.

How do I get the column name from an Entity Framework Association

I have an entity model built using the designer. In one of my tables (application), I have several foreign keys that reference the same status (status) table. As a result, when my associations were built, I have several entity objects built with an auto indexing name:
application_statuses2
application_statuses3
etc.
I'm building a "version history" type screen and want to be able to properly list the "friendly name" for each column modified. For example, I want to display "Destination Status" will be displayed instead of "application_statuses2". If I can determine the endpoint column name on the association in question, I can setup the proper display value.
I can find the entity object in the designer, I can even track where it references the foreign key in question that built the association, but I can seem to find the property that outlines the enpoints or column names. How do I determine the column name, or endpoint, on my association, or entity?
I wish it were more ready to hand, have been looking for it as well. Bit of a pain when you have multiple FKs to the same table.
Click on the navigation property you want to check
Under properties, look at the name of the association
At the top of properties, use the object navigator dropdown to switch to the association
Click into the 'Referential Constraint' property
Use the ellipses button on the right to bring up the column names
Dont know if there is a better way of doing this, but I certainly hope so!

How to bind multiple tables to a binding navigator using data source wizard in C#

How to bind multiple tables to a binding navigator using data source wizard in C# so that when textbox1 value changes the values in other textboxes should be change which contains data from other table. tables have foreign key relationships.
The BindingNavigator should have a BindingSource value set to the BindingSource object of your "parent" or "master" table in the dataset (same as textBox1). The "other table" controls should have a BindingSource object that points to the "child" datatables. If your relationships are properly setup then when you change the master/parent record with the bindingnavigator then the detail/child records will update accordingly
Basically, the binding source for your "other tables" should have a DataSource value pointing to the BindingSource of your primary table (the binding source of textbox1) and
should have a DataMember value of the relationship/FK that points to the respective secondary table.
If you are using drag and drop datasources then be sure you are dragging over the data sources that utilize the relationships. So say you created a dataset with 3 tables with tiered relationships: Grandparent, Parent, Child. In your Data Sources window you will see all three datatables side by side. You are probably dragging the desired Grandparent field over and getting your binding navigator, binding source, and textbox created, correct? You might think you are supposed to then use those side-by-side root-level Parent and Child datasources but that is WRONG. Expand the Grandparent source and at the end of columns listed you will see Parent listed again nested underneath Grandparent. Expand that and use those columns. At the bottom of that nested Parent you will see a Child data source that you can expand and use columns from.