[英]How to set Option List value on new CRM 2011 Entity record with Linq?
我正在C#中創建新的實體記錄。 問題是我早綁定的Xrm類期望問題列表中的整數值,但是我所擁有的只是選擇列表的字符串值。
所以,這就是我想要做的。 問題是“ OptionListValue”是整數值。 你懂; 自動創建的巨大。
是我找出該特定期權價值的唯一方法嗎? 如果是這樣,我將使用什么API來獲取它以及如何使用它? 我期望有一些Linq方法可以這樣做。 但是我可能承擔的太多了。
public void CreateNewContactWithOptionListValue(string lastName, string theOptionListValue)
{
using ( var context = new CrmOrganizationServiceContext( new CrmConnection( "Xrm" ) ) )
{
var contact = new Contact()
{
LastName = lastName,
OptionListValue = theOptionListValue // How do I get the proper integer value from the CRM?
};
context.Create( contact );
}
}
不使用Web服務的方法:
public void CreateNewContactWithOptionListValue(string lastName, string theOptionListValue)
{
using (var context = new CrmOrganizationServiceContext(new CrmConnection("Xrm")))
{
new_customoptionset parsedValue;
if (!Enum.TryParse<new_customoptionset>(theOptionListValue, out parsedValue))
{
throw new InvalidPluginExecutionException("Unknown value");
}
var contact = new Contact()
{
LastName = lastName,
OptionListValue = new OptionSetValue((int)parsedValue)
};
context.Create(contact);
}
}
注意選項標簽中的空格,因為它們在枚舉中已被刪除
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.