Rhetos.ComplexEntity 6.0.0

Prefix Reserved
dotnet add package Rhetos.ComplexEntity --version 6.0.0
                    
NuGet\Install-Package Rhetos.ComplexEntity -Version 6.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rhetos.ComplexEntity" Version="6.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Rhetos.ComplexEntity" Version="6.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Rhetos.ComplexEntity" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Rhetos.ComplexEntity --version 6.0.0
                    
#r "nuget: Rhetos.ComplexEntity, 6.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Rhetos.ComplexEntity@6.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Rhetos.ComplexEntity&version=6.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Rhetos.ComplexEntity&version=6.0.0
                    
Install as a Cake Tool

Rhetos.ComplexEntity

ComplexEntity is a DSL package (a plugin module) for Rhetos development platform. It provides functionality for manipulation with complex entities (such as master-detail) in same transaction. In order to work properly it introduces several concepts needed to implement this functionality - Function, Object and ListOf.

Contents:

  1. Installation and configuration
  2. ComplexStructure, Detail and Extension
    1. Using ComplexEntity in Domain Object Model
  3. Function
  4. Object and ListOf
  5. How to contribute
    1. Building and testing the source code

See rhetos.org for more information on Rhetos.

Installation and configuration

Installing this package to a Rhetos application:

  1. Add 'Rhetos.ComplexEntity' NuGet package, available at the NuGet.org on-line gallery.
  2. Extend the Rhetos services configuration (at services.AddRhetosHost) with the ComplexEntity components: .AddComplexEntity()

ComplexStructure, Detail and Extension

ComplexStructure, Detail and Extension are DSL concepts which, in combination, provide functionality of retrieving and saving complex hierarchical data. That data can consist of several entities that have some kind of relation on to the other. Relationships that can be used are Detail and Extends. ComplexStructure replaces obsolete ComplexEntity DSL concept.

ComplexStructure concept creates a copy of the specified DataStructure and provides means to add complex hierarchical properties to it.

Detail concept creates ComplexStructure of the specified DataStructure and ListOf property to parent ComplexStructure.

Extension concept creates ComplexStructure of the specified DataStructure and Object property to parent ComplexStructure.

CreateGet concept creates a Function for retrieving an instance of specified ComplexStructure. Input parameter is ID of 'master' entity. Additionally, concept AfterGet is provided that allows you to insert your code before returning result for postprocess purposes like filling additional data (see example bellow).

CreateSave concept creates Function for saving an instance of specified ComplexStructure, and also creates CreateGet. Input parameter is specified ComplexStructure itself. Output parameter is also the same ComplexStructure with updated propagated ID-s throughout the object hierarchy. Additionally, concepts BeforeSave and AfterSave are provided that allows you to insert your code before and after save sequence for preprocess and postprocess purposes.

Example:

Module ComplexStructures
{
    Entity MasterEntity
    {
        ShortString Title;
    }

    Entity ExtensionEntity
    {
        Extends ComplexStructures.MasterEntity;
        ShortString OrderNumber;
    }

    Entity DetailEntity
    {
        Reference MasterEntity { Detail; }
        ShortString Description;
    }

    Entity SubDetailEntity
    {
        Reference DetailEntity { Detail; }
        ShortString PartNumber;
    }


    ComplexStructure MasterComplex ComplexStructures.MasterEntity
    {
        Integer DetailCount;
        
        Detail ComplexStructures.DetailEntity Details    //created ComplexStructure name is MasterDetailsComplex
        {
            Detail ComplexStructures.SubDetailEntity Details;    //created ComplexStructure name is MasterDetailsDetailsComplex
        }

        Extension ComplexStructures.ExtensionEntity Extension;    //created ComplexStructure name is MasterExtensionComplex

        Bool PerformPostValidation;

        CreateGet
        {
            AfterGet 'FillAdditionalData'
            '
                root.DetailCount = root.Details.Count;
            ';
        }
        CreateSave    //created Function name for save is MasterComplexSave, and for get is MasterComplexGet
        {
            BeforeSave ValidateData
            '
                if (parameters.Item.Details == null || !parameters.Item.Details.Any())
                    throw new Rhetos.UserException("Entity must have at least one detail.");
            ';

            AfterSave SomeAfterSaveValidation
            '
                if (parameters.Item.PerformPostValidation.GetValueOrDefault())
                {
                    // some after save optional validation
                    // throw new Rhetos.UserException("Some validation description."); - this exception rollbacks entire transaction, nothing is saved
                }
            ';
        }
    }
}

Using ComplexEntity in Domain Object Model

After reading How to execute examples you can try this example of saving and loading with ComplexEntity that uses DSL described above:

void Main()
{
    ConsoleLogger.MinLevel = EventType.Info; // Use "Trace" for more detailed log.
    var rhetosServerPath = Path.GetDirectoryName(Util.CurrentQueryPath);
    Directory.SetCurrentDirectory(rhetosServerPath);
    // Set commitChanges parameter to COMMIT or ROLLBACK the data changes.
    using (var container = new RhetosTestContainer(commitChanges: false))
    {
        var context = container.Resolve<Common.ExecutionContext>();

        var complex = new ComplexStructures.MasterComplex
        {
            Title = "My first complex entity",
            Details = new List<ComplexStructures.MasterDetailsComplex>
            {
                new ComplexStructures.MasterDetailsComplex {Description = "Detail a"},
                new ComplexStructures.MasterDetailsComplex
                {
                    Description = "Detail b",
                    Details = new List<ComplexStructures.MasterDetailsDetailsComplex>
                    {
                        new ComplexStructures.MasterDetailsDetailsComplex { PartNumber = "the part number 1" },
                        new ComplexStructures.MasterDetailsDetailsComplex { PartNumber = "the part number 2" }
                    }
                }
            },
            Extension = new ComplexStructures.MasterExtensionComplex { OrderNumber = "123"},
            PerformPostValidation = false
        };

        //save complex entity
        var result = context.Repository.ComplexStructures.MasterComplexSave.Execute(new ComplexStructures.MasterComplexSave { Item = complex });

        //load complex entity
        var loaded = context.Repository.ComplexStructures.MasterComplexGet.Execute(new ComplexStructures.MasterComplexGet { ID = result.ID });
    }
}

Function

The Function concept allows adding custom web API methods to the Rhetos REST service.

It is similar to Action concept, except it allows you to return some result. Additional parameter specifies type of return value. For example:

Module Functions
{
    Entity Post
    {
      ShortString Title;
      LongString Content;
    }

    Function CreateNewPost Functions.Post //returns instance of type Functions.Post
    '(parameter, repository, userInfo) =>
    {
        var content = parameter.Content ?? "Default Content";

        var post = new Functions.Post
        {
          Title = parameter.Title,
          Content = content,
        };

        repository.Functions.Post.Insert(post);

        return post;
    }'
    {
        ShortString Title;
        LongString Content;
    }
}

Object and ListOf

Object is a DSL concept which allows you to define a DataStructure property that is a reference type of another DataStructure.

ListOf is DSL concept which allows you to define a DataStructure property that is a list of type of another DataStructure or simple property (ShortString, Integer, etc.). In C# Domain Object Model it is represented as List<T>.

Example:

Module Functions
{
    Entity Post
    {
        ShortString Title;
        LongString Content;
    }

    Parameter ReturnValue
    {
        ShortString SomeValue;
        Object Functions.Post Post;
        ListOf Functions.Post AdditionalPosts;
        ListOf ShortString Contributors;
    }
}

How to contribute

Contributions are very welcome. The easiest way is to fork this repo, and then make a pull request from your fork. The first time you make a pull request, you may be asked to sign a Contributor Agreement. For more info see How to Contribute on Rhetos wiki.

Building and testing the source code

  • Note: This package is already available at the NuGet.org online gallery. You don't need to build it from source in order to use it in your application.
  • To build the package from source, run Clean.bat, Build.bat and Test.bat.
  • For the test script to work, you need to create an empty database and a settings file test\Rhetos.ComplexEntity.TestApp\rhetos-app.local.settings.json with the database connection string (configuration key "ConnectionStrings:RhetosConnectionString").
  • The build output is a NuGet package in the "Install" subfolder.
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Rhetos.ComplexEntity:

Package Downloads
Rhetos.OmegaCommonConcepts

This package is a plugin for Rhetos development platform.

Rhetos.ElasticSearch

This package is a plugin for Rhetos development platform.

Rhetos.FloydExtensions

This package is a plugin for Rhetos development platform.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
6.0.0 105 9/3/2025
5.1.0 2,387 3/16/2023
5.0.0 2,803 3/25/2022
1.4.0 543 1/26/2022
1.3.0 343 12/27/2021
1.2.1 822 1/19/2021
1.2.0 1,452 10/25/2020
1.1.0 1,022 5/14/2020