I just started using the ability to store XAF application model changes in the database (using the ModelDifference class). By default, it seems that changes made in the web version are shared with the win version (and vice versa).
I would like to have my win and web version changes to be separate. So if a user changes some ordering of columns on the Web side, this will not affect that same ordering of columns on the Win side.
I think I've got this working but wanted to confirm with you that this is a valid solution:
- I subclassed the ModelDifference class with a separate class for Module.Win (ModelDifferenceWin) and Module.Web (ModelDifferenceWeb):
C#[MapInheritance(MapInheritanceType.OwnTable)]
public class ModelDifferenceWin : ModelDifference
{
public ModelDifferenceWin(DevExpress.Xpo.Session session)
: base(session)
{
}
}
- In WinModule.cs and WebModule.cs, I changed the ModelDifferenceType (below is the Win version)
C#public TestDBModelDec19WindowsFormsModule() {
InitializeComponent();
//ModelDifferenceDbStore.ModelDifferenceType = typeof(ModelDifference);
ModelDifferenceDbStore.ModelDifferenceType = typeof(ModelDifferenceWin);
}
ModelDifferenceDbStore.ModelDifferenceType = typeof(ModelDifferenceWin); }This seems to be working for me… the user settings changes in the Win are not affecting the Web side. Can you see any problems with this solution?
Turns out I needed to create my own custom ModelDifference and ModelDifferenceAspect classes. Just subclassing as I did above resulted in a shared table that was trying to insert both a win and a web difference record for the same user… this resulted in a "duplicate User Id" error since the UserId field in the database is marked as unique for the table.
Hi Richard,
>> this resulted in a "duplicate User Id" error since the UserId field in the database is marked as unique for the table.
I could not replicate this error at the database level, because there is currently no unique constraint for the UserId column. However, the validation error may occur at the UI level due to the validation attribute of this field. In my tests with ModelDifferenceWin/Web descendants, there was a situation when there were multiple records in the ModelDifference table with the same UserId value. You can avoid this by implementing the IModelDifference interface from scratch.
We think that this particular scenario with different places for storing WinForms and ASP.NET settings can be implemented more easily, so you may be interested in tracking the Application Model - Make it easier to store user settings in the database for WinForms and Web applications separately request on our TODO list.
Thanks, yes it was the Validation attribute that was reporting the error. I'll track that new ticket as well as it looks much easier =), and for now I'll just implement the IModelDifference interface from scratch.
Thanks for your feedback, Richard.
Merry Christmas!