Skip to content

Simple Models

In Coalesce, any data class exposed by Coalesce that is not a CRUD Model is considered to be a "simple model". Simple models are just plain data objects and do not have any API endpoints or other advanced functionality.

INFO

Simple Models used to be called External Types prior to Coalesce v6. Their functionality did not change.

The set of simple models in a Coalesce application looks like this:

  1. Take all of the exposed property types, method parameters, and method return types of your CRUD Models, as well as method parameters and returns from Services.
  2. Any of these types which are not built-in scalar types and not one of the aforementioned CRUD models are simple models.
  3. Types explicitly marked with [Coalesce, SimpleModel] are also discovered as simple models.
  4. For any simple model discovered, any of the property types which qualify under the above rules are also simple models.

WARNING

Be careful when using types that you do not own for properties and method returns in your data model. When Coalesce generates simple model ViewModels and DTOs, it will not stop until it has exhausted all paths that can be reached by following public property types and method returns.

In general, you should only expose types that you have created so that you will always have full control over them. Mark any properties you don't wish to expose with [InternalUse], or make those members non-public.

Generated Code

For each simple model found in your application's model, Coalesce will generate:

Example Data Model

For example, in the following scenario, these classes are considered simple models:

  • ReportParameters, exposed through a method parameter on ReportService.
  • ReportResponse, exposed through a method return on ReportService.
  • ReportSummary, exposed through a property on ReportResponse.
  • ReportSettings, explicitly marked with [SimpleModel].
c#
[Coalesce, Service]
public class IReportService {
    public SalesReport GenerateSalesReport(ReportParameters parameters);
}

public class ReportParameters { 
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
    public string Category { get; set; }
}

public class SalesReport { 
    public ReportSummary Summary { get; set; }
    public string[] Data { get; set; }
}

public class ReportSummary { 
    public int TotalRecords { get; set; }
    public DateTime GeneratedAt { get; set; }
}

// Explicitly include this type as a Simple Model
[Coalesce, SimpleModel]
public class ReportSettings { 
    public string Format { get; set; }
    public bool IncludeCharts { get; set; }
    public string Theme { get; set; }
}

Loading & Serialization

Simple Models have slightly different behavior when undergoing serialization to be sent to the client. Unlike CRUD Models types which are subject to the rules of Include Tree, simple models ignore the Include Tree when being mapped to DTOs for serialization. Read Simple Model Caveats for a more detailed explanation of this exception.


Coalesce is a free and open-source framework created by IntelliTect to fill our desire to create better apps, faster. IntelliTect is a high-end software architecture and development consulting firm based in Spokane, Washington.

If you're looking for help with your software project, whether it be a Coalesce application, other technologies, or even just an idea, reach out to us at info@intellitect.com — we'd love to start a conversation! Our clients range from Fortune 100 companies to local small businesses and non-profits.