Larry Caylor
|
|
Group: Awaiting Activation
Posts: 592,
Visits: 3.7K
|
While I really like what I’ve learned about the framework to date I’m still having some problems understanding the best way to apply it. I think most of my issues surround object mapper and its one object to one table relationship. For example I’m wondering what is the best way to address the following situation using StrataFrame. I have three tables, User, Role, and Role Assignment. RoleAssignment maintains a many to many relationship between User and Role and in addition to it’s primary key only contains the foreign keys to the other tables. I want to display user and role assignments in a list view. In another framework I would have created a read-only object that would contain user names, roles, along with the associated keys and any additional information I wished to get from the User and Role tables, and populated it using a stored procedure. However since object mapper only maps one object to one table this presents a problem. I suppose one solution would be to create a complex business object. I could also drop all the objects on the form and maintain the relationship between them on the form. My goal is to insulate the UI developer from the underlying data structure as much as possible. Any suggestions? While this example is for a read only object, I have the same questions when dealing with multiple editable objects on a form. Finally does MicroFour plan on offering any formal training classes or consulting services in the future? -Larry
|
|
|
Gary Wynne
|
|
Group: Forum Members
Posts: 10,
Visits: 40
|
Hi Larry >I have three tables, User, Role, and Role Assignment. RoleAssignment maintains a many to many relationship between User and Role and in addition to it’s primary key only contains the foreign keys to the other tables. OK, RoleAssignment is a standard link table. >I want to display user and role assignments in a list view ... However since object mapper only maps one object to one table this presents a problem. One way to present this would be in the form of a SQL server view. Right now, I don't know whether the object mapper will allow you to specify/read a view but I cannot see why not. This way, you could "persist" the query in the view and present the BO mapper with a single entity to map. >While this example is for a read only object, I have the same questions when dealing with multiple editable objects on a form. You could use a view to "present" the data to the BOs and have custom stored procedures to update the back-end. In this way, if there are mutiple tables to update, you can house the required logic to achieve this in the stored procedure. I hope I am not way off base here and that I have interpreted your question correctly  Best -=Gary
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
Larry,
The way I build my list view is like this:
1) Add a FillUsersAndRoles() method to the RoleAssignment business object. This method would call a join that would bring in the username and rolename.
2) In your PopulationDataSourceSettings for the list view, add the columns for "UserName" and "RoleName" (notice the combo box is not a dropdown list, so you can type in whatever field name you need.
3) If the field is in the internal DataTable of the business object and doesn't have a corresponding custom field, the list view will still find it when the list is populated.
So, just make sure the business object is filled with the information from the join, and configure the PopulationDataSourceSettings the same way you normally would, you'll just have to type in the field name(s) rather than selecting them from the dropdown list.
As for the training... we're cranking away on the training videos that will be available online, and we're still considering whether or not we will provide online/onsite training classes.
|
|
|
Larry Caylor
|
|
Group: Awaiting Activation
Posts: 592,
Visits: 3.7K
|
Thanks for the suggestions. I hadn’t considered using a view, but it turns out that object mapper will let you select a view. Looking forward to the training videos. -Larry
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
Looking forward to the training videos. So am I, Larry  As for the view, you can build a business object off of the view if you're using SQL Server as your schema, but you can't if you're using the Database Deployment Toolkit for your schema; we don't support that, yet
|
|
|
Larry Caylor
|
|
Group: Awaiting Activation
Posts: 592,
Visits: 3.7K
|
Okay I understand how to fill the business object to bring in the additional fields from other tables to populate the list view. What I’m not clear on is updating and saving the object. If I didn’t have additional fields I would drop the object on the form, populate it, and then populate the list view from the existing object on the form to save an extra trip to the database. However if I try the same approach using a business object containing extra fields I receive a “The given key was not present in the dictionary” error message when I try to save the object. I’m assuming that this is a result of having the extra columns on the underlying data table and the fact that they are really defined in the business object. So do I solve this by having two instances of the business object, one for updating and one with additional fields for populating the list view? -Larry
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
Yes, a business object can have any structure you define when you're working with the business object locally (whether it matches a structure in the database or not). However, any business object that attempts to save to a table in the database must match the table's structure.
|
|
|
Larry Caylor
|
|
Group: Awaiting Activation
Posts: 592,
Visits: 3.7K
|
I’m still wrestling with the situation where I require fields from other tables for display purposes and the fact that the business object must match the single table structure in the DB to save it. It would be nice if there were a way to mark individual fields as savable or not, or if the object were smart enough to only try and save/update fields defined by object mapper, allowing you to have a single instance of an object that could provided the required behaviors without being so closely tied to the underlying data structure. However I imagine doing so would require some significant changes to the framework. Therefore my question what is the recommended approach to handle this situation? Should I create two instances of the object, one that includes fields from other tables for display purposes and one without for updating? Or should I simply add the other objects/tables to my form and pull the added fields from them on the form? Most of what I’m doing is manipulating a List View to allow the user to work with the information is a user friendly way before saving the results (mostly just foreign keys) to the DB. Some other solutions come to mind, but I’d like your input on what is the most efficient way to do this within SF.
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
Yes, generally we iterate through the fields within the internal data table to save, however, it would not be hard to iterate through the AllFieldsList collection rather than the columns on the DataTable... would probably be faster as well. I'll take a look and see what sort of enhancement this would require. You also might have your "savable" business object standing by. You could clear it and then use the MergeDataFrom method to copy only in only the columns that should be saved on the business object. private void SaveRecords() { //-- Clear the business object being used to save SavingBO.Clear(); //-- Copy in the data to be saved from the list view bo SavingBO.MergeDataFrom(ListViewBO, MergeDataTableOptions.MergeFromCompleteTable_ReplaceExistingDuplicates); //-- Save the business object as it will only have the columns that can be saved SavingBO.Save(); } Hope this helps
|
|
|
Larry Caylor
|
|
Group: Awaiting Activation
Posts: 592,
Visits: 3.7K
|
Ben, Thanks for the “MergeDataFrom method” suggestion; I’ll give it a try. However iterating through the AllFieldsList collection rather than the columns on the DataTable when saving would be a great enhancement. Being able to work with a single instance rather than two would simplify code and make it easier to understand -Larry
|
|
|