Designer Shortcuts and Tips
You can add a new property to an entity by pressing the Ins key while the entity or any of its properties is selected.
You can set the type of a property by entering the type name before the property name when editing the property, as if declaring a C# variable. For example, if you type int Height, then the property is named Height and is of type Int32.
As in C#, you can use the question mark suffix to make the property nullable (e.g. int? Height).
Using the Ins key and inline type editing, you can easily enter multiple properties without taking your hands away from the keyboard. This can be much quicker than using the mouse when entering a lot of properties.
You can apply custom attributes to generated properties using the various Custom Attributes collections. You can set custom attributes on entities and properties via the Custom Attributes option, and for associations you can set them on either end of the association and the foreign key (via options such as Collection Custom Attributes and Backreference Id Custom Attributes).
Custom attributes are applied to the wrapper property, not the backing field. Most LightSpeed attributes have to go on the backing field, so you can’t use custom attributes to apply LightSpeed attributes – it’s usually more convenient to use the designer equivalents anyway. Rather, they are intended for attributes consumed by other frameworks, such as BrowsableAttribute or DisplayNameAttribute.
When you enter an attribute in the Custom Attributes dialog, you must fully qualify the attribute name, e.g. System.ComponentModel.Browsable. If you’re applying a lot of attributes from the same namespace, you can get around this by adding the namespace to the Imported Namespaces list (via the LightSpeed Model Explorer).
To get an image of your entire model, press Ctrl+C or choose Edit > Copy. You can then paste this into Word, PowerPoint or Paint as a bitmap.
If you want only a subset of your model, select the elements you want to include in the image before copying.
If you are filtering the view, the copied image will show only the elements that are included in the current filter.
The toolbox includes a ‘reminder’ icon which you can use to add notes to your model. You can link a note to a URL by filling out the Link URL property; in this case, the note will display a More… link which takes you to that URL. For example, a “to do” note could be linked to an entry in a bug tracking system.
Once you’ve hooked your model up to a database, you can use the Get Started command to see the LightSpeed configuration file entries. You can paste from the Get Started screen into your web.config or app.config. Be aware that the provided entries are a starter set: you may still need to configure other settings by hand, such as identityMethod or quoteIdentifiers.
To rearrange entries in an entity’s properties list – for example, to alphabetise them or to group related items together – right‑click a property and choose Move Up or Move Down.
To assign a keyboard shortcut to a LightSpeed designer command:
· Open Tools > Options > Environment > Keyboard, or Tools > Customize > Keyboard.
· In the “Show commands containing” checkbox, enter LightSpeed.
· The list box shows a list of LightSpeed designer commands.
· Choose the command you want, type the desired keystroke into the “Press shortcut keys” box and click Assign.
· When you’ve finished mapping commands, click OK.
There are two ways to use a custom base class for your entities.
One way is to create the base class normally using the designer, draw inheritance arrows and set the inheritance type to Concrete Table Inheritance. This works well with designer-database synchronisation because the designer can know about fields defined in the base class, but for larger models can result in a lot of arrows cluttering up the diagram. If the clutter becomes a problem, you can hide these arrows by selecting them and setting Show On Diagram to false.
The alternative approach is to define the base class in code, create an External Class Reference to that class via the LightSpeed Model Explorer, and set each entity’s Base Class to the external reference via the Properties window. This avoids lots of inheritance arrows, but will result in a warning that the external class is being excluded each time you sync to the database.
If you want to change the name of a property or entity in the domain model, but you have lots of code that already uses the existing name, and you don’t want to change the database schema either, you can use the Refactor > Rename command to help you out. Right-click the property or entity and choose Refactor > Rename. Enter the new name and make sure that “Keep existing name as database column/table name” is ticked. LightSpeed will update all references to the property or entity in your code, and create a mapping between the renamed element and the existing database name.
To write custom code for property getters and setters, select the property you need to write custom code for, go to the Properties window and change the Generation option to FieldOnly. You can then write your own property getter and setter in the partial class. You can also right-click the property and choose Refactor > Convert to Manual Implementation; however, this will also convert the backing field to a manual implementation, which will prevent LightSpeed from applying subsequent changes to property settings.
To set validation options that aren’t available in the Properties window, like ValidateUriAttribute.UriKind or custom error messages, use the LightSpeed Model Explorer to locate the validation, and edit its properties. See Validation in the Creating Domain Models chapter for details.
Foreign Key Field Attribute in Designer
From LightSpeed 5 onwards the designer supports setting the ForeignKeyFieldAttribute on one-to-one associations.
Right-clicking on an entity and selecting ‘Show Data’ will open the Visual Studio table editor, allowing you to view the table data for that entity. This is available for SQL Server, MySQL and SQLite. For non-SQL Server databases you will need to have the appropriate Visual Studio integration package installed. For this to work you will need to have a connection to the database defined in the Server Explorer (which you will be prompted to create if you’re going the model-first route).