Mindscape
  • Register
  • Login
  • YOUR CART IS EMPTY
home
Software
  • Developers Toolbox
  • LightSpeed
  • Raygun
  • WPF Elements
  • Web Workbench
  • Metro Elements
  • Silverlight Elements
  • NHibernate Designer
  • Phone Elements
  • WPF Diagrams
  • Simple DB management
  • Visual Tools for SharePoint
Downloads
Store
  • Buy online
  • Purchase order
  • Volume discounts
  • Reseller
  • Software license
  • Contact sales
Blog
Support
About
  • About Us
  • Contact
  • Testimonials
rss
twitter
facebook
Working with Models in the Visual Designer LightSpeed Model Explorer Workflows for Rapid Application Development Enums and Other User8209Defined Types Enums and Other User Defined Types Refactoring in the Designer Custom Views Linked Models Changing the Designer Defaults Customising the Generated Code ManytoMany Associations Designer Shortcuts and Tips

Linked Models

Another solution to the problem of large, complex models is to replace a single model file with multiple linked model files. Linked model files work well when your domain consists of a number of distinct subdomains, with relatively few links across subdomain boundaries.  Don’t use linked model files if you have a lot of associations across subdomain boundaries – cross-file associations require quite a bit of maintenance and if you have too many of them you may find they are more trouble than they are worth!

To link a set of model files, you must do two things:

·         Set the Name of each model to the same value. (If you are specifying a namespace in the model, then this must be the same for all of the linked models too.)

·         Choose one of the models to be the “main” model. For all of the other models, set Is Linked Child to True.

If you use the Paste as Link command to create entity links, or the Refactor > Split Model At Association command to split an existing model into two files, it will set these properties for you.

Code Generation

Each linked model file in a set is code-generated separately.  The code generation is done in such a way that the generated files combine to produce a single model using partial classes.  For example, you will end up with a single strong-typed unit of work class, with queryable properties for all of the entity types, although the implementation for this class will be spread across three files.

Because LightSpeed depends on partial classes to combine code, all linked model files must be in the same project.

Creating Associations Across Model File Boundaries

You can represent an entity from one file in another file by dragging an Entity on from the Toolbox and setting its Name to the desired linked entity, and settings its Is Link property to True. You can then create associations to the linked entity. You must create the associations in both files.

For example, suppose you have two files, Sales.lsmodel and Logistics.lsmodel. The Sales subdomain contains an entity named PurchaseOrder and the Logistics subdomain contains an entity named Shipment. You want to create a one-to-many association between these entities, so that a PurchaseOrder has a collection of Shipments and a Shipment has a reference to a PurchaseOrder. To do this:

·         Open Sales.lsmodel and drag on an Entity from the Toolbox.

·         Set the entity’s Name to Shipment and Is Link to True.

·         Click OneToManyAssociation in the Toolbox and drag an arrow from PurchaseOrder to Shipment.

·         Open Logistics.lsmodel and drag on an Entity from the Toolbox.

·         Set the entity’s Name to PurchaseOrder and Is Link to True.

·         Click OneToManyAssociation in the Toolbox and drag an arrow from PurchaseOrder to Shipment.

·         Save both models and rebuild your project.

Creating and Maintaining Entity Links

A quick way to create a link is to select the “main” entity definition, choose Edit > Copy or press Ctrl+C, switch to the target file, right-click the model background and choose Paste as Link. This will automatically set up the entity link’s properties, and can also link the two model files for you.

Important: An entity link is not aware of the entity it links to. Therefore, you must manually keep properties in sync between the link and the original entity. In particular, if the entity has an Identity Type other than Int32, you must set the Identity Type on the link to be the same as the Identity Type on the entity. If you are using model-first database synchronisation or migrations, and the entity overrides the Table Name, Identity Column Name or Schema, then you must also replicate these settings to the link. You can check that these settings are in sync using the Check Links menu command.

To see the definition of a linked entity, right-click the link and choose Go To Linked Entity.

Data Products

  • LightSpeed ORM
  • NHibernate Designer
  • SimpleDB Tools
  • SharePoint Tools

DevOp Tools

  • Raygun

Visual Controls

  • WPF Elements
  • WPF Diagrams
  • Silverlight Elements
  • Phone Elements

Popular Products

  • Web Workbench

    Modern web development for Visual Studio!

  • Mindscape Megapack

    All Mindscape products for one awesome price!

Quick Links

  • Forums
  • Blog
  • Register
  • Login
  • Contact us
  • Twitter
  • Facebook
  • Google+
  • YouTube
  • Linkedin
  • Rss

© Mindscape 2025. Mindscape is a registered trademark of Mindscape Limited.

  • Terms
  • Privacy