protected void ExecutePreMyEntityUpdate(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}
IPluginExecutionContext context = localContext.PluginExecutionContext;
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
Xrm.my_entity entity= entity.ToEntity<Xrm.my_entity >();
IOrganizationService service = localContext.OrganizationService;
using (var ctx = new XrmServiceContext(service))
{
var query = ctx.my_entityRelatedSet.SingleOrDefault(f => f.field1 == "some_value");
throw new Exception(query.field2.ToString());
}
}
- my_entityRelatedSet - entity related N:1 with my_entity.
- XrmServiceContext - generated with crmsvcutil.exe
Thank you for your opinion,
Laurentiu