简体   繁体   English

CRM 2011自定义工作流Linq查询,当它们不为空时提供空值

[英]CRM 2011 Custom Workflow Linq Queries providing null values when they are not null

I am writing a Custom Workflow for MS Dynamics CRM 2011. In my workflow I have a class that I use specifically for queries – this is because I do a significant number of quires for other methods within the workflow. 我正在为MS Dynamics CRM 2011编写自定义工作流。在我的工作流中,我有一个专门用于查询的类–这是因为我对工作流中的其他方法进行了大量的查询。 For my queries I am using LINQ. 对于我的查询,我正在使用LINQ。

I ran into an issue in my testing where I have two methods that go out and get a different option set values. 我在测试中遇到一个问题,我有两种方法可以退出并获得不同的选项集值。 They both work if tested individually. 如果单独测试,它们都可以工作。 However, if I test them back to back … get this option set value…then get this option set value: The subsequent query always returns a null. 但是,如果我背对着它们进行测试……获取此选项设置值……然后获取此选项设置值:后续查询始终返回null。

<!-- language: cs -->
public int GetOptionSetValues(WorkFlowHelper workFlowHelper, String bracketId)
{
     Guid _bracketId = workFlowHelper.GuidChanger(bracketId);
     var query = from b in workFlowHelper.serviceContext.myEntitySet
                 where b.myEntitySetId.Equals(_bracketId)
                 select new { b.itemToGetOptionSetFrom };
     foreach (var qin query )
     {
       if (q.itemToGetOptionSetFrom == null)
       {
        return 0;
       }
       else
       {
        int optionSetValue = q.itemToGetOptionSetFrom;
        return optionSetValue;
       }
     }
      return 0;
 }

Both methods are the same as above with the exception of "itemToGetOptionSetFrom" is different. 除了“ itemToGetOptionSetFromFrom”不同之外,这两种方法都与上述相同。 I have checked the DB and the items do infact have values. 我已经检查了数据库,并且这些项目确实具有值。

Can anyone explain why this is doing this? 谁能解释为什么这样做呢? Or point me in the right direction to correct this issue? 还是指出正确的方向来纠正此问题? Thanks, 谢谢,

I'm guessing you're retrieving the same object with the same service context. 我猜您正在检索具有相同服务上下文的相同对象。 If you request an attribute(s) from an entity, the CRMContext will cache a copy of that entity with only those fields and the id. 如果从实体请求属性,则CRMContext仅使用那些字段和ID缓存该实体的副本。 This means all subsequent LINQ requests that include that entity will return the cached copy of that entity that ONLY includes the id and attributes you previously requested. 这意味着包括该实体的所有后续LINQ请求将返回该实体的缓存副本,该副本仅包含您先前请求的ID和属性。 To avoid this you can call ClearChanges() to remove the cached version before making your next request. 为避免这种情况,您可以在发出下一个请求之前,调用ClearChanges()删除缓存的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM