Dynamics crm 2011 Crm属性。包含返回意外值的函数

Dynamics crm 2011 Crm属性。包含返回意外值的函数,dynamics-crm-2011,Dynamics Crm 2011,在插件中,当消息名为update时,我必须保存字段值,字段类型为decimal和currency。但是当我检查字段是否包含值时,意外地包含返回实体集合的函数,对于其他返回querybyattribute类型的属性,即使变量是bool,它也可以得到不同类型的值,并且如果子句不起作用。是什么原因造成的 if (entity.Attributes.Contains("new_flighthotelreservationid")) { IOrganizationServiceF

在插件中,当消息名为update时,我必须保存字段值,字段类型为decimal和currency。但是当我检查字段是否包含值时,意外地包含返回实体集合的函数,对于其他返回querybyattribute类型的属性,即使变量是bool,它也可以得到不同类型的值,并且如果子句不起作用。是什么原因造成的

 if (entity.Attributes.Contains("new_flighthotelreservationid"))
     {
       IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); 
       IOrganizationService orgService = factory.CreateOrganizationService(context.UserId);

        bool b = entity.Attributes.Contains("new_poscost");//to check what is returning
        bool c = entity.Attributes.Contains("profittl");

        Decimal posTutarı5 = entity.Attributes.Contains("new_poscost") ? ((Money)entity.Attributes["new_poscost"]).Value : 0m;

        Decimal profitTl5 = entity.Attributes.Contains("new_profittl") ? (Decimal)entity.Attributes["new_profittl"] : 0m;

        Decimal totalAmount5 = entity.Attributes.Contains("new_totalamount") ? ((Money)entity.Attributes["new_totalamount"]).Value : 0m;

好的,以下是我到目前为止所理解的:


new_flighthotelreservationid是类型查找,因此:


仅当new_flighthotelreservationid不为NULL时,才会执行if

您还可以分析和检查:

因此,将值分配给十进制变量存在问题: 尝试以下方法:

如果您的字段是decimal类型

如果您的字段类型为“货币”

下面是获得货币价值的另一种方法


new_flighthotelreservationid字段的类型是什么?要检查ifcondition中的值,必须首先分析。new_flighthotelreservationid是查找类型。在if子句中,我正在检查实体的new_flighthotelreservationid属性是否包含值,我是否需要对此进行分析。我将如何同时分析和签入if子句。以两种方式if子句都返回true。问题是将值赋给十进制变量有什么问题。我正在检查属性中是否存在该值。如果存在,则分配属性值;如果不存在,则分配0。但在这些代码行工作之后,十进制变量仍然是空的。
if (entity.Attributes.Contains("new_flighthotelreservationid"))   //Check if NULL
{
           //So flight reservation is not NULL
           //Below is to parse lookup
EntityReference Resrv = (EntityReference)entity["new_flighthotelreservationid"];

}

else
{
       //Flight reservation is NULL
}
if (((EntityReference)entity["new_flighthotelreservationid"]).Id != null)
{
//Not NULL
}
Decimal posTutarı5 = (Decimal)(entity.Attributes.Contains("new_poscost")?entity["new_poscost"] : 0m);
Money posTutarı5 = (Money)(entity.Attributes.Contains("new_profittl") ? entity["new_profittl"] : 0m);
Money NewProfit=entity["new_profittl"] as Money;
int retailPrice = NewProfit.Value;