This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello, Does a T4 template exist that is equivalent to that of NVelocity generating entities and the UnitOfWork class? In essence, I'd like to use T4 rather than NVelocity to generate code as we are already using T4 for other things. Thanks, Werner |
|
|
Hello, In case there isn't an equivalent, would you be so kind to provide me with some snippets to detmine the following?
Or perhaps you can point me to some documentation. I looked around but fail to find anything that can help. Unfortunally none of the T4 editors I tried does proper autocompletion for the Lightspeed members. Much appreciated. Werner PS. I have been working from this example: http://www.mindscapehq.com/forums/Post.aspx?ThreadID=3070&PostID=11067 |
|
|
Hi Werner, Have you tried following this post about working with T4 Templates and LightSpeed? http://www.mindscapehq.com/blog/index.php/2010/04/12/using-t4-templates-with-lightspeed/ You can probably ascertain from the current NVelocity templates what the properties are you want off the model to see what is available. Out of interest, why are you wanting to move to T4? Just curious. John-Daniel Trask |
|
|
Hello, Almost everyone here knows T4 and no one has worked with NVelocity, so it makes sense (for maintainability sake) to use T4. I already looked at the blog post you provided as well as several other forum posts. Unfortunately, they do not provide enough information for me to complete the task at hand. For example, I'm unable to port the NVelocity templates directly to T4. It seems that some members, such as Inflector and StringUtils are marked internal and not usable. The NVelocity templates also reference fields collection on entities, which doesn't exist seem to exist in the "Entity" class used in the T4 template. Using Object Viewer, I'm unable to find the "Entity" class being used in the T4 template. So I'm a tad confused as to what's going on. I'm sure I'm missing something simple. What changes should I make to my T4 template to use the same object model as those use by the NVelocity templates? I already have approx 15 T4 templates which tries to generate anything from controllers to view models, resource files etc from a LightSpeed model. However, its not really that maintainable nor is it complete. Much appreciated. Werner
|
|
|
The NVelocity templates don't work off the .lsmodel object model: there's another component which transforms the .lsmodel object model into something that is closer to what we need for code generation (e.g. mapping the various designer options into a uniform model of CLR attributes). This allows us to reduce the complexity of the templates a bit. This is why you see members in the NVelocity templates that don't exist on .lsmodel entities -- some of the naming differs between the .lsmodel object model and the 'low level' object model (for annoying historical reasons). If you want to inspect the 'low level' object model, you can find it in Mindscape.LightSpeed.Generator.Model.dll, but we don't currently provide a way for T4 to access the 'low level' version of the object model -- the transformation between the two versions is bound up with the NVelocity generator. We can look at breaking out an API that will get you the low level form, and some measure of access to the injected objects such as Inflector. Alternatively, you can implement your own transforms to create your own 'low level' model, which may better line up with your desired output. You can pull in open source libraries such as Inflector.NET to handle most of the name manipulation stuff. This requires more effort but allows you to create a nicer API for T4 to consume if you are doing specialised stuff like extension properties (and does not depend on us finding the time to refactor the existing generator). Again, we can consider exposing some of the components within our transformation layer (e.g. the attribute mapper) so you could reuse those without having to take on the whole of the NVelocity model. Let us know how you want to proceed. By the way, one caveat around maintainability is that we do sometimes update the templates. It's easy to replicate these changes to custom NVelocity templates using a diff tool, but if you've ported the templates to T4 then you won't be able to just diff them. You'll be pretty much on your own. Obviously, you may judge that the time saved by not having to learn NVelocity justifies the increased maintenance risk and effort (after all, we don't update the templates very often!), but it's something to bear in mind when figuring out how you'll be maintaining the custom templates. |
|
|
Thanks Ivan, In that case, would you mind to help me out? In which assembly is the Entity class used in the T4 sample in the blog? I'd like to know whether the following is set on an entity?
And for properties
To provide background, I'm generating a view model in order to get around a JSON serialization issue when one has interdepdent relationships. The view model is almost identical to the entity, except that it doesn't have any relationships (with exception of depdendant relationships). Regards, Werner |
|
|
The T4 samples we have posted all run against the .lsmodel object model, which is in the Mindscape.LightSpeed.Generator.Integration.Dsl DLL. So that's where you'll find the Entity object used in the T4 samples (which, as you have found, is different from the Entity type used in the NVelocity templates). You'll find that the Entity properties in the .lsmodel object model correspond pretty closely to what you see in the Properties window. For example, to find out if Track Create Time is set, check the Entity.TrackCreateTime property. (By contrast, the NVelocity model represents this as a CreatedOn field.) Similarly for the other special fields, the Entity.Namespace property and the Property.IsNullable property. "Include in Full Text Index" is known in the object model as Property.Indexed. The PluralName will only be set on an Entity if it has been explicitly specified. So to determine the effective plural name, you will need to check Entity.PluralName, and if that is null or empty, use Inflector.NET to pluralise the Entity.Name. Unfortunately Andrew Peters' original Inflector.NET no longer seems to be available but I can provide you with a copy (attached to this post). For validations, the UI and the object model diverge, basically to provide a nicer UI. In the object model, a property has a Validations collection. For example, a Validate Value setting might map to a ComparisonValidation or a RangeValidation object in the Validations collection. Similarly if Validate Unique is set to true then that maps to a UniquenessValidation in the Validations collection. To examine the 'real' implementation of validations, go to the LightSpeed Model Explorer, expand a property node and poke around in its Validations folder -- that's what T4 will see. (Again, in NVelocity we transform these designer objects to the corresponding LightSpeed attributes before invoking the template.) Does that all make sense? Let me know if you need any more info! |
|
|
Thanks Ivan, this helps. Werner
|
|