在CRM 4.0检索单个的Guid [英] Retrieving a single Guid in CRM 4.0
问题描述
我是新来的 CRM(版本4.0)
,我想返回基于特定年份对yearid指南(这也是存储在实体)。到目前为止我已经得到了:
I'm new to CRM (version 4.0)
and i'm trying to return a 'yearid' guide based on a given year (which is also stored in the entity).So far i've got:
public static Guid GetYearID(string yearName)
{
ICrmService service = CrmServiceFactory.GetCrmService();
// Create the query object.
QueryExpression query = new QueryExpression("year");
ColumnSet columns = new ColumnSet();
columns.AddColumn("yearid");
query.ColumnSet = columns;
FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.And;
filter.AddCondition(new ConditionExpression
{
AttributeName = "yearName",
Operator = ConditionOperator.Equal,
Values = new object[] { yearName}
});
query.Criteria = filter;
}
但是我的问题是:
A)除了做这个代码什么实际存储的GUID?
B)是使用QueryExpression最有效的方式做到这一点?
But my questions are:
A) What code do in addition to this to actually store the Guid?
B) Is using a QueryExpression the most efficient way to do this?
推荐答案
回复:b)去为sql也许更快(我没有多少甚至是否),但我本来以为在situtations 99%的QueryExpression是在性能方面完全可以接受知道
Re: B) Going to sql maybe faster (I don't know by how much or even if), but I would have thought in 99% of situtations a QueryExpression is perfectly acceptable in terms of performance.
回复:A)Your're非常接近,我已经完成了下面的代码
Re: A) Your're pretty close, I have completed the code below.
public static Guid GetYearID(string yearName)
{
ICrmService service = CrmServiceFactory.GetCrmService();
// Create the query object.
QueryExpression query = new QueryExpression("year");
//No need to ask for the id, it is always returned
//ColumnSet columns = new ColumnSet();
//columns.AddColumn("yearid");
//query.ColumnSet = columns;
FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.And;
filter.AddCondition(new ConditionExpression
{
AttributeName = "yearName",
Operator = ConditionOperator.Equal,
Values = new object[] { yearName}
});
query.Criteria = filter;
//We have to use a retrieve multiple here
//In theory we could get multiple results but we will assume we only ever get one
BusinessEntityCollection years = service.RetrieveMultiple(query);
DynamicEntity year = (DynamicEntity)years.BusinessEntities.First();
return ((Guid)year["yearid"]);
}
这篇关于在CRM 4.0检索单个的Guid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!