Views, Auto-Lightweight and the Modeler
In a previous post we saw how to create views and lightweight entities by using XML. Nowadays most of you are using the graphical modeler, so let’s see how to create views.
First, let’s create a simple model:
We can create a view that contains the supplier name and the country name. Select the supplier entity and click the “Add view” button from the ribbon:
You should see the following window:
Enter a valid name and select properties to include in the view. Only properties from the selected entity are shown. So to add the country name, we have to click the “Add” button and enter the binding expression “Country.Name” (auto completion prevents mistakes).
The « Auto infer lightweight entity » checkbox allows to generate an entity that contains selected properties. As the name suggests it’s a light entity: it’s not persistent, it has no CRUD methods (e.g. load, save, delete) nor extra properties by default, and it does not implement any interfaces other than the ICodeFluentLightEntity by default.
Now we can create a method that will load data from this view:
The generated code contains the SQL view :
CREATE VIEW [dbo].[vSupplierSupplierLight] AS SELECT [Supplier].[Supplier_Name], [Country].[Country_Name] AS 'CountryName' FROM [Supplier] INNER JOIN [Country] ON ([Supplier].[Supplier_Country_Id] = [Country].[Country_Id])
And the inferred lightweight entity:
The R&D team