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
|
Hi, I have been using Lightspeed within VS2005 by manually creating my classes with an : Entity<int> at the end etc. All works fine. I've now installed VS2008 and have the Lightspeed modeller available within that version. I have upgraded my VS2005 project to VS2008 and thought I'd upgrade all the entities and their code to the new look of the lightspeed designer. Is this easy to do? I tried to add a new Lightspeed model but it didn't pick up all my old classes and I couldn't drag them on to the designer. Do I have to start from scratch if I want the designer available? Thanks, Craig
|
|
|
The designer doesn't operate directly on C# or Visual Basic code: it has its own representation (the .lsmodel format) and then generates C# or Visual Basic code from that. So it's more like the XSD designer than the Class Diagram feature. Fortunately, in current nightly builds, there is an experimental command-line tool in the installation directory (under Tools / Designer) called lsgetmodel.exe, which you can run over an assembly containing a LightSpeed model to extract this into a .lsmodel file. (If you can't see it, you probably have an older build -- download the latest nightly from the Downloads tab.) Please note this is experimental and has primarily been written to support synchronising databases to code-based models. We don't guarantee this will pick up everything from your existing model and it may just blow up on some models! But it's probably worth a go. (If you do get errors, please send us your assembly so we can update lsgetmodel to handle these cases -- thanks!) Once you've run this over your assembly you can then add the generated .lsmodel to your project. Note that if you add the .lsmodel to the project where the classes are already defined, you will get a lot of compiler errors because Visual Studio will be generating class and property declarations from the .lsmodel and these will duplicate your handcrafted classes and properties. Depending on the size of your model and whether you have custom business logic in the existing classes and properties, there are a couple of approaches you could take to resolving this and we would be happy to advise. Also, lsgetmodel doesn't try to generate a nicely laid out diagram. You'll probably need to drag things around a bit before you can see the model properly. Finally, since you have a working project and presumably therefore an existing database, another option is simply to drag database tables from Server Explorer onto the designer -- this may be easier than using lsgetmodel and is definitely more robust! |
|
|
[quote user="ivan"]Finally, since you have a working project and presumably therefore an existing database, another option is simply to drag database tables from Server Explorer onto the designer -- this may be easier than using lsgetmodel and is definitely more robust! This is the option I took. I have my model diagram now but when I compile it is obviously conflicting with my existing classes..."another partial declaration of this type exists". I have lots of code in these objects as well what would be the best approach for this? Thanks, Craig |
|
|
It depends on the nature of the code. The designer wants to generate two things: entity classes and entity members. Let's take these separately. You can't stop the designer generating entity classes: all you can do is cooperate. That means adding the partial modifier to each of your entity class declarations. (You may also need to remove the access modifier, e.g. public or internal, from your declarations, and will need to remove the base class declarations.) This will enable the C# compiler to merge the generated code with your code at compile time. E.g. where you have: public class Product : Entity<int> { ... } you would change this to: partial class Product { ... } Now for the entity members. How you handle these will depend on the code you already have, so again let's take it case by case: 1. For handwritten fields and properties (including associations) which are just LightSpeed boilerplate with no domain logic in them, you can just delete these fields and properties from the handwritten partial class. The designer is already generating the boilerplate declarations for you. (To get a feel for this, open the generated .cs or .vb file and have a look at the generated code. You'll easily get the idea of which of your handwritten fields and properties can be replaced with generated code.) 2. For handwritten fields and properties (including associations) which include custom domain logic in the getters or setters, you can tell the designer not to generate its own code, thus allowing you to keep your code. To do this, select the property or association in the designer, go to the Properties window and change Generation to None. (For future info, you can also change Generation to FieldOnly which means the designer will generate the field but you can write your own property wrapper. This is handy if you want custom logic but still want the designer to emit things like validation or lazy load attributes. It's probably not relevant for your current case though.) 3. For handwritten properties or methods that don't appear in the designer (e.g. helper methods or calculated properties), you don't need to do anything. If you have a large model, and figuring out which is which and selectively deleting code sounds like too much effort or too much risk, you can just set *everything* to Generation=None. (The .lsmodel file is just XML so you can even write a script to do this for you instead of having to click on everything.) Obviously, this makes the designer a bit futile as far as the existing parts of your model are concerned, but it frees you to add new stuff via the designer, and/or to delete boilerplate incrementally as you work on your project rather than stop work and do a big-bang migration. Hope that gives you some idea of how to tackle this -- please do ask if you need further guidance or if you run into difficulties or doubts. |
|
|
Perfect...makes total sense. Thanks, Craig |
|