/
Strongly-typed entities
Strongly-typed entities
Classes can inherit from FuseIT.S4D.DynamicsConnector.Entities.EntityBase to define strongly-typed entity objects.
using FuseIT.S4D.DynamicsConnector.Metadata;
// The Entity attribute defines the Dynamics 365 entity name.
[Entity("contact")]
class Contact : EntityBase<Contact>
{
// Makes the emailaddress1 field available as an object property, with a type.
public string email
{
get => (string)this["emailaddress1"];
set { this["emailaddress1"] = value; }
}
public string firstname
{
get => (string)this["firstname"];
set { this["firstname"] = value; }
}
public string lastname
{
get => (string)this["lastname"];
set { this["lastname"] = value; }
}
// Any fields not explicitly defined are still accessible via the Dictionary syntax.
// e.g. this["contactid"]
}
This also allows use of alternate query expression syntax.
var session = serviceFactory.GetSessionFromConnectionString("MyDynamicsInstance");
// Find a contact by email address.
var contact = await Contact.LoadSingleAsync(session,
(query, exp) =>
{
ODataExpression filterExpression = (exp.email == "example@example.com");
ODataExpression[] selectExpression = new ODataExpression[] { exp.firstname, exp.lastname };
query.Filter(filterExpression).Select(selectExpression);
}
);
// Returned objects have strongly-type fields where defined.
Console.WriteLine($"First name: {contact.firstname}, Last name: {contact.lastname}");
, multiple selections available,
Related content
Dynamics 365 metadata
Dynamics 365 metadata
Read with this
Dynamics 365 configuration
Dynamics 365 configuration
Read with this
Custom development
Custom development
Read with this
S4D Identify Contact Submit Action
S4D Identify Contact Submit Action
Read with this
Generic entities
Generic entities
Read with this
Install S4D
Install S4D
Read with this