gebeurtenis
Power BI DataViz World Championships
14 feb, 16 - 31 mrt, 16
Met 4 kansen om in te gaan, kun je een conferentiepakket winnen en het naar de LIVE Grand Finale in Las Vegas maken
Meer informatieDeze browser wordt niet meer ondersteund.
Upgrade naar Microsoft Edge om te profiteren van de nieuwste functies, beveiligingsupdates en technische ondersteuning.
When you work with the SDK for .NET assemblies, you have two programming styles you can use: late-bound and early-bound.
The key difference between early and late binding involves type conversion. While early binding provides compile-time checking of all types so that no implicit casts occur, late binding checks types only when the object is created or an action is performed on the type. The Entity class requires types to be explicitly specified to prevent implicit casts.
Late binding allows you to work with custom tables (entities) or columns (attributes) that weren't available when your code was compiled.
Late-bound programming uses the Entity class where you need to refer to table rows and columns (entities and attributes) using their LogicalName
property values:
Relationships don't have a LogicalName
property, so the RelationshipMetadataBase.SchemaName property is used.
The main advantage for late-bound programming is that you don't need to generate the classes or include that generated file within your projects. The generated file can be large.
The main disadvantages are:
Tip
A tool that you can use to find this information easily is the Metadata Browser. This is an app you can download and install in your organization. More information: Browse the metadata for your environment
The following example creates an account using the late-bound style.
//Use Entity class specifying the entity logical name
var account = new Entity("account");
// set attribute values
// string primary name
account["name"] = "Contoso";
// Boolean (Two option)
account["creditonhold"] = false;
// DateTime
account["lastonholdtime"] = new DateTime(2017, 1, 1);
// Double
account["address1_latitude"] = 47.642311;
account["address1_longitude"] = -122.136841;
// Int
account["numberofemployees"] = 500;
// Money
account["revenue"] = new Money(new decimal(5000000.00));
// Picklist (Option set)
account["accountcategorycode"] = new OptionSetValue(1); //Preferred customer
//Create the account
Guid accountid = svc.Create(account);
Early-bound programming requires that you first generate a set of classes based on the table and column definitions (entity and attribute metadata) for a specific environment using the code generation tool Power Platform CLI pac modelbuilder build command. More information: Generate classes for early-bound programming using the SDK for .NET
After generating early-bound classes using the code generation tool, you'll enjoy a better experience while you write code because classes and properties use the respective SchemaName
property values:
Simply instantiate the class and let Visual Studio IntelliSense provide the names of properties and relationships.
The classes generated for early-bound programming can also include definitions for any custom actions that are defined for the environment. This provides you with a pair of request and response classes to use with these custom actions. More information: Custom Actions
Classes are generated using table definitions from a specific environment instance and each instance may have different tables and columns where these can change over time. You may need to write code to work for tables that aren't present when you generate the strongly typed classes.
Belangrijk
If you are using the OrganizationServiceProxy to provide the IOrganizationService methods you will use, you must call the OrganizationServiceProxy.EnableProxyTypes() method to enable early bound types.
The following example creates an account using the early-bound style.
var account = new Account();
// set attribute values
// string primary name
account.Name = "Contoso";
// Boolean (Two option)
account.CreditOnHold = false;
// DateTime
account.LastOnHoldTime = new DateTime(2017, 1, 1);
// Double
account.Address1_Latitude = 47.642311;
account.Address1_Longitude = -122.136841;
// Int
account.NumberOfEmployees = 500;
// Money
account.Revenue = new Money(new decimal(5000000.00));
// Picklist (Option set)
account.AccountCategoryCode = new OptionSetValue(1); //Preferred customer
//Create the account
Guid accountid = svc.Create(account);
Which programming style you choose to use is up to you. The following table provides the advantages and disadvantages for each.
Early-bound | Late-bound |
---|---|
You can verify entity, attribute, and relationship names at compile time | No compile time verification of entity, attribute, and relationship names |
You must generate entity classes | You don't need to generate entity classes |
Better IntelliSense support | Less IntelliSense support |
Less code to write; code is more readable | More code to write; code is less readable |
Very slightly less performant | Very slightly more performant |
Because all the generated classes inherit from the Entity class used with late-bound programming, you can work with entities, attributes, and relationships not defined within classes.
The following example shows one way to mix early and late binding methods using OrganizationServiceContext.
// Create an context object
AWCServiceContext context = new AWCServiceContext(_serviceProxy);
// Instantiate an account object using the Entity class.
Entity testaccount = new Entity("account");
// Set several attributes. For account, only the name is required.
testaccount["name"] = "Fourth Coffee";
testaccount["emailaddress1"] = "marshd@contoso.com";
// Save the entity using the context object.
context.AddToAccountSet(testaccount);
context.SaveChanges();
If a custom attribute wasn't included in the generated classes, you can still use it.
var account = new Account();
// set attribute values
// string primary name
account.Name = "Contoso";
// A custom boolean attribute not included in the generated classes.
account["sample_customboolean"] = false;
//Create the account
Guid accountid = svc.Create(account);
The following sample shows how to assign an early bound instance to a late bound instance.
Entity incident = ((Entity)context.InputParameters[ParameterName.Target]).ToEntity<Incident>();
Task relatedEntity = new Task() { Id = this.TaskId };
incident.RelatedEntities[new Relationship("Incident_Tasks")] =
new EntityCollection(new Entity[] { relatedEntity.ToEntity<Entity>() });
Entity operations using the SDK for .NET
Create table rows using the SDK for .NET
Retrieve a table row using the SDK for .NET
Query data using the SDK for .NET
Update and delete table rows using the SDK for .NET
Associate and disassociate table rows using the SDK for .NET
IOrganizationService Interface
Using OrganizationServiceContext
gebeurtenis
Power BI DataViz World Championships
14 feb, 16 - 31 mrt, 16
Met 4 kansen om in te gaan, kun je een conferentiepakket winnen en het naar de LIVE Grand Finale in Las Vegas maken
Meer informatieTraining
Leertraject
Use advance techniques in canvas apps to perform custom updates and optimization - Training
Use advance techniques in canvas apps to perform custom updates and optimization
Certificering
Microsoft Gecertificeerd: Dynamics 365 Business Central Developer Associate - Certifications
Demonstreert u de vaardigheden om oplossingen te ontwerpen, ontwikkelen, testen en onderhouden op basis van Dynamics 365 Business Central.
Documentatie
Learn how to create early bound entity classes with the code generation tool, CrmSvcUtil.exe, for Dynamics 365 Customer Engagement (on-premises).
Generate early-bound classes for the SDK for .NET - Power Apps
Learn how to use the Power Platform CLI pac modelbuilder build command to generate early-bound classes for use with the Microsoft Dataverse SDK for .NET. This tool generates early-bound .NET classes that represent the Entity Data Model used by Dataverse.
IOrganizationService Interface (Microsoft Dataverse) - Power Apps
Learn about the common web service methods exposed to perform data operations in Microsoft Dataverse.