YC.DynamicsMapper 2.0.7-beta

This is a prerelease version of YC.DynamicsMapper.
dotnet add package YC.DynamicsMapper --version 2.0.7-beta                
NuGet\Install-Package YC.DynamicsMapper -Version 2.0.7-beta                
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="YC.DynamicsMapper" Version="2.0.7-beta" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add YC.DynamicsMapper --version 2.0.7-beta                
#r "nuget: YC.DynamicsMapper, 2.0.7-beta"                
#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.
// Install YC.DynamicsMapper as a Cake Addin
#addin nuget:?package=YC.DynamicsMapper&version=2.0.7-beta&prerelease

// Install YC.DynamicsMapper as a Cake Tool
#tool nuget:?package=YC.DynamicsMapper&version=2.0.7-beta&prerelease                

NuGet

Using the SourceGenerator

This document provides a brief overview of how to use the source generator to generate mapper classes for your entity classes.

Step 1: Define Your Entity Classes

First, you need to define your entity classes and decorate them with the CrmEntity and CrmField attributes. These attributes specify the mapping between your entity classes and the corresponding CRM entities.

For example, here is a sample Person class decorated with the CrmEntity and CrmField attributes:

[CrmEntity("person")]
public class Person
{
    [CrmField("personid", Mapping = MappingType.PrimaryId)]
    public Guid PersonId { get; set; }

    [CrmField("firstname")]
    public string? FirstName { get; set; }

    [CrmField("lastname")]
    public string? LastName { get; set; }
}

Step 2: Run the Source Generator

The source generator is executed automatically when you build your project. This will generate the mapper classes for each of your entity classes. The mapper classes implement the IEntityMapper<TEntity> interface and are responsible for mapping between your entity classes and the corresponding CRM entities.

Step 3: Use the Mapper Classes

Once the mapper classes have been generated, you can use them to map between your entity classes and the CRM entities. To do this, you need to create an instance of the appropriate mapper class and call its Map methods.

For example, here is how you might use the PersonMapper class to map between a Person object and a CRM entity:

var person = new Person { PersonId = Guid.NewGuid(), FirstName = "John", LastName = "Doe" };
var mapper = new PersonMapper();
var entity = mapper.Map(person);

You can also use the Map method to map from a CRM entity to a Person object. Here is an example:

var entity = new Entity("person");
entity.Id = Guid.NewGuid();
entity["firstname"] = "Jane";
entity["lastname"] = "Doe";

var mapper = new PersonMapper();
var person = mapper.Map(entity);

Mapping Types

  • Basic: This is the default mapping type and is used for simple data types such as strings, integers, and booleans.
  • Lookup: This mapping type is used for lookup fields in the CRM entity. A lookup field is a field that references another entity record.
  • Money: This mapping type is used for money fields in the CRM entity. A money field is a field that stores currency values.
  • Formatted: This mapping type is used for formatted fields in the CRM entity. A formatted field is a field that has a specific format, such as a date or time field.
  • Options: This mapping type is used for option set fields in the CRM entity. An option set field is a field that allows the user to select from a predefined set of options.
  • MultipleOptions: This mapping type is used for multi-select option set fields in the CRM entity. A multi-select option set field is a field that allows the user to select multiple options from a predefined set of options.
  • PrimaryId: This mapping type is used for the primary ID field of the CRM entity. The primary ID field is the unique identifier for the entity record.
  • DynamicLookup: Similar to Lookup just without a target, for lookups with multiple targets ('customer' / 'regardingobjectid') the target is specified by sending DynamicsMappingsTargets to the mapping function.
  • DynamicLookupTarget: This mapping type is returnung the target of a dynamic lookup such as 'regardingobjectid'.

In addition to the CrmEntity and CrmField attributes, you can also use the CrmLink attribute to map linked entities. This attribute allows you to establish relationships between different entities in your CRM.

Here's how you can use it:

[CrmEntity("order")]
public class Order
{
    [CrmField("orderid", Mapping = MappingType.PrimaryId)]
    public Guid OrderId { get; set; }

    [CrmField("totalamount")]
    public decimal? TotalAmount { get; set; }

    [CrmLink("person")]
    public Person Person { get; set; }
}

In the example above, the Order class has a Person property that represents the person associated with the order. The CrmLink attribute is used to specify that this property maps to a linked entity in the CRM.

And that's it! You can now use the source generator to generate mapper classes for your entity classes and easily map between your entity classes and the corresponding CRM entities.

Settings (DynamicsMapperSettings)

  • DefaultValueHandling: When this setting is set to 'Ignore', when mapping a model to entity all the default values are ignored.
  • Mappers: Let you customize the mapping process by implementing one or more of the mappers.

Mappers Inetfaces

  • IBasicMapper
  • IFormattedValuesMapper
  • IMoneyMapper
  • IOptionsetMapper
  • IOptionSetValueCollectionMapper
  • IPrimaryIdMapper
  • ILookupMapper
  • IDynamicLookupTargetMapper

** every mapper interface is used for the equivalent mapping type ** the DynamicLookupTarget mapping type is using the ILookupMapper

FastMappers

Why?

FastMappers is a new way to map Entities to models when you need to map only a small part of the full model.

Entity To Model Mappers

There is a performance issue when initializing a large model when only few properties are needed.

Model To Entity Mappers

When mapping a large model to Entity there is a problem with default values, there is no way to know if this field is requierd for mapping.

For example: If we have a contact model and we need to delete it's first name there is no good way of doing that. We can't ignore default values and there is no way to distinct the firstname attribute from all the other attributes, this will reslut with a deletion of all of the unused properties of the model.

How?

Fastmappers are using Linq Expressions to resolve the required fields and mappings to compile a runtime function to map Entities to anonymus objects and visecersa.

Mapping to model

The MapperFactory will produce a FastModelMapper where the Map function is compliled at runtime resulting an efficiant mapping process an a low memory footprint

Mapping to entity

The MapperFactory will produce a FastEntityMapper where only the predefined properties are mapped.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.7-beta 102 6/30/2024
2.0.6-beta 99 6/28/2024
2.0.4-beta 109 6/16/2024
2.0.0-beta 94 6/14/2024
1.1.4 633 3/5/2024
1.1.3 240 2/13/2024
1.1.0 108 2/9/2024
1.0.9 642 11/14/2023
1.0.8 163 10/21/2023
1.0.7 164 9/30/2023
1.0.6 196 8/7/2023
1.0.6-beta 144 8/6/2023

* Added FastMappers
     * Can map directly to another object
     * FastToEntityMappers are using models instead of the source model
     * Supporst unequal names between Model and destination
     * Strong named DynamicsMapper.FastMappers