David Fowler (2011-08-23)
I have been looking at code generated view models and have found them potentially useful, but they are missing some features which mean they are no use to me in my projects.
#1 The ability to use specify PS expressions on columns.
#2 The ability to use code-derived expressions on columns.
#3 A simple way to use struct types in view model columns. (see thread http://www.capableobjects.com/apps/InstantForum414/Topic6209-4-1.aspx I never got a satisfactory answer to that one)
Are any of these features planned for the future?
#1
Nah- this requirement pops up from time to time - having PS-derived values. The thing is that no one can come up with a generic idea on when to invalidate them - so they will be stale and old real quick.
How we usually handle this is by modeling like this:
ACodeDerivedAssociationThatDoesAPSFetch
ADerivedAttributeThatCanTriggerTheInvalidationOfTheAbove (with set and get)
Then the ACodeDerivedAssociationThatDoesAPSFetch can subscribe to the ADerivedAttributeThatCanTriggerTheInvalidationOfTheAbove and I can set a new value in the ADerivedAttributeThatCanTriggerTheInvalidationOfTheAbove and after that read ACodeDerivedAssociationThatDoesAPSFetch and trust that it will be refetched.
Consider this case:
AllEmployeesThatDid40HoursLastWeek -> Employee
AllEmployeesThatDid40HoursLastWeekFreshnessTime
ateTime
First time I read AllEmployeesThatDid40HoursLastWeek it is fetched and also set the AllEmployeesThatDid40HoursLastWeekFreshnessTime to Now. I can then read AllEmployeesThatDid40HoursLastWeek multiple times and it is the cached value.
Then I can set the AllEmployeesThatDid40HoursLastWeekFreshnessTime to Now (or whatever as long as I change it) and the next time I read AllEmployeesThatDid40HoursLastWeek it will be refetched...
#2
I suggest that you code derive in your Model and use those Attributes in the ViewModel. On the otherhand I think we will make the Code generated ViewModel "partial" so that you can have your own code logic in the correct ViewModelClass
#3
To use a struct declared in another assembly:
Go like this:
<Type CanonicalName="ClassLibrary1.Coord" Type="ClassLibrary1.Coord,
ClassLibrary1, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=5348474bcfb2dae2">
<CommonName Name="Coord" CaseSensitive="false"/>
<CommonName Name="ClassLibrary1.Coord" CaseSensitive="false"/>
<LanguageName Language="C#" Name="ClassLibrary1.Coord"/>
<LanguageName Language="Delhpi" Name="ClassLibrary1.Coord"/>
<LanguageName Language="Oxygene" Name="ClassLibrary1.Coord"/>
<LanguageName Language="VB" Name="ClassLibrary1.Coord"/>
</Type>
The Canonical name must match the name you use in the model.
When you do this the viewmodel gets generated like so:
public ClassLibrary1.Coord Coordinate {
get {
return
((ClassLibrary1.Coord)(((Eco.ViewModel.Runtime.VMNativeTypeAttribute)(this["
Coordinate"])).Value));
}
set {
((Eco.ViewModel.Runtime.VMNativeTypeAttribute)(this["Coordinate"])).Value =
value;
}
}