当前位置: 首页>>代码示例>>C#>>正文


C# Entity.Contains方法代码示例

本文整理汇总了C#中System.Entity.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Entity.Contains方法的具体用法?C# Entity.Contains怎么用?C# Entity.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Entity的用法示例。


在下文中一共展示了Entity.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestContains

        public void TestContains()
        {
            Entity entity = new Entity();
            entity.Add(new ComponentA());
            Assert.AreEqual(true, entity.Contains<ComponentA>());

            entity.Remove<ComponentA>();
            Assert.AreEqual(false, entity.Contains<ComponentA>());
        }
开发者ID:Djadavin,项目名称:Primal,代码行数:9,代码来源:EntityTests.cs

示例2: SetAutonumbers

 public void SetAutonumbers(Entity entity)
 {
     var autonumbers = GetActiveAutonumbersForType(entity.LogicalName);
     foreach (var autonumber in autonumbers)
     {
         if (autonumber.OverwriteIfPopulated
             || !entity.Contains(autonumber.AutonumberField))
             SetAutonumber(entity, autonumber);
     }
 }
开发者ID:josephmcmac,项目名称:JosephM.Xrm.Autonumber,代码行数:10,代码来源:AutonumberService.cs

示例3: ReplicateWithFields

 public static Entity ReplicateWithFields(Entity entity, IEnumerable<string> fieldsToSubmit)
 {
     var submissionEntity = new Entity(entity.LogicalName) {Id = entity.Id};
     if (fieldsToSubmit != null)
     {
         foreach (var field in fieldsToSubmit)
         {
             if (entity.Contains(field))
                 XrmEntity.SetField(submissionEntity, field, XrmEntity.GetField(entity, field));
         }
     }
     return submissionEntity;
 }
开发者ID:josephmcmac,项目名称:JosephM.Xrm,代码行数:13,代码来源:XrmService.cs

示例4: Create

 public void Create(Entity entity, IEnumerable<string> fieldsToSubmit)
 {
     if (fieldsToSubmit != null && fieldsToSubmit.Any())
     {
         var submissionEntity = new Entity(entity.LogicalName) {Id = entity.Id};
         foreach (var field in fieldsToSubmit)
         {
             if (entity.Contains(field))
                 XrmEntity.SetField(submissionEntity, field, XrmEntity.GetField(entity, field));
         }
         Create(submissionEntity);
     }
 }
开发者ID:josephmcmac,项目名称:JosephM.Xrm,代码行数:13,代码来源:XrmService.cs

示例5: ToJSON

        public static string ToJSON(Entity entity, Formatting format, int indent)
        {
            StringBuilder sb = new StringBuilder();
            var space = format == Formatting.Indented ? " " : "";
            sb.Append(
                Sep(format, indent + 0) + "{" + space +
                Sep(format, indent + 1) + "\"entity\":" + space + "\"" + entity.LogicalName + "\"," +
                Sep(format, indent + 1) + "\"id\":" + space + "\"{" + entity.Id.ToString() + "}\"," +
                Sep(format, indent + 1) + "\"attributes\":" + space + "[");

            bool first = true;
            foreach (KeyValuePair<string, object> attribute in entity.Attributes)
            {
                Object value = attribute.Value;
                if (attribute.Key == entity.LogicalName + "id")
                {
                    continue;
                }
                if (attribute.Key.EndsWith("_base") && entity.Contains(attribute.Key.Substring(0, attribute.Key.Length - 5)))
                {
                    continue;
                }

                if (first)
                {
                    sb.Append(Sep(format, indent + 2) + "{");
                    first = false;
                }
                else
                    sb.Append("," + Sep(format, indent + 2) + "{");

                if (value is AliasedValue)
                {
                    if (!string.IsNullOrEmpty(((AliasedValue)value).AttributeLogicalName))
                    {
                        sb.Append(Sep(format, indent + 3) + "\"attributelogicalname\":" + space + "\"" + (((AliasedValue)value).AttributeLogicalName) + "\",");
                    }
                    if (!string.IsNullOrEmpty(((AliasedValue)value).EntityLogicalName))
                    {
                        sb.Append(Sep(format, indent + 3) + "\"entitylogicalname\":" + space + "\"" + (((AliasedValue)value).EntityLogicalName) + "\",");
                    }
                    value = (((AliasedValue)value).Value);
                }

                sb.Append(Sep(format, indent + 3) + "\"name\":" + space + "\"" + attribute.Key + "\",");
                sb.Append(Sep(format, indent + 3) + "\"type\":" + space + "\"" + LastClassName(value) + "\",");

                if (value is EntityReference)
                {
                    sb.Append(Sep(format, indent + 3) + "\"entity\":" + space + "\"" + ((EntityReference)value).LogicalName + "\",");
                    if (!string.IsNullOrEmpty(((EntityReference)value).Name))
                    {
                        sb.Append(Sep(format, indent + 3) + "\"namevalue\":" + space + "\"" + ((EntityReference)value).Name + "\",");
                    }
                    value = ((EntityReference)value).Id;

                }

                if (value != null)
                {
                    sb.Append(string.Format(Sep(format, indent + 3) + "\"value\":" + space + "\"{0}\"", AttributeToBaseType(value)));
                }

                sb.Append(Sep(format, indent + 2) + "}");
            }
            sb.Append(Sep(format, indent + 1) + "]");
            sb.Append(Sep(format, indent + 0) + "}");
            return sb.ToString();
        }
开发者ID:Innofactor,项目名称:CRMWinForm,代码行数:69,代码来源:EntitySerializer.cs

示例6: GetEntityName

        private string GetEntityName(Entity e)
        {
            try
            {
                var entityName = string.Empty;

                if (e.Contains("privilegeobjecttypecode.objecttypecode"))
                {
                    var alias = e.GetAttributeValue<AliasedValue>("privilegeobjecttypecode.objecttypecode");

                    entityName = alias != null ? alias.Value as string : string.Empty;
                }

                if (!string.IsNullOrEmpty(entityName))
                {
                    var entityMetadata = _entityMetadata
                        .Where(m => m.LogicalName == entityName)
                        .FirstOrDefault();

                    if (entityMetadata != null &&
                        entityMetadata.DisplayName != null &&
                        entityMetadata.DisplayName.UserLocalizedLabel != null)
                    {
                        entityName = entityMetadata.DisplayName.UserLocalizedLabel.Label;
                    }
                }

                return entityName;
            }
            catch
            {
                MessageBox.Show("Error encountered in GetEntityName");
                return "ERROR";
            }
        }
开发者ID:gotdibbs,项目名称:magician,代码行数:35,代码来源:ControlViewModel.cs

示例7: ReplaceParameters

        private string ReplaceParameters(string text, Entity Target, IOrganizationService Service)
        {
            if (String.IsNullOrWhiteSpace(text))
            {
                return "";
            }

            foreach (RuntimeParameter param in RuntimeParameter.GetParametersFromString(text))
            {
                if (!param.IsParentParameter())
                {
                    text = text.Replace(param.ParameterText, param.GetParameterValue(Target));
                }
                else
                {
                    if (Target.Contains(param.ParentLookupName))
                    {
                        var parentRecord = Service.Retrieve(Target.GetAttributeValue<EntityReference>(param.ParentLookupName).LogicalName, Target.GetAttributeValue<EntityReference>(param.ParentLookupName).Id, new ColumnSet(param.AttributeName));
                        text = text.Replace(param.ParameterText, param.GetParameterValue(parentRecord));
                    }
                    else  // Target record has no parent, so use default value
                    {
                        text = text.Replace(param.ParameterText, param.DefaultValue);
                    }
                }
            }

            return text;
        }
开发者ID:BESDev,项目名称:Celedon-Autonumber-RTM,代码行数:29,代码来源:GetNextAutoNumber.cs

示例8: GetParameterValue

        public string GetParameterValue(Entity Target)
        {
            if (Target.Contains(AttributeName))
            {
                if (Target[AttributeName] is EntityReference)
                {
                    // Lookup condition is based on GUID
                    return Conditional.HasCondition ? Conditional.GetResult(Target.GetAttributeValue<EntityReference>(AttributeName).Id) : Target.GetAttributeValue<EntityReference>(AttributeName).Name;
                }
                else if (Target[AttributeName] is OptionSetValue)
                {
                    // Conditional OptionSetValue is based on the integer value
                    return Conditional.HasCondition ? Conditional.GetResult(Target.GetAttributeValue<OptionSetValue>(AttributeName).Value.ToString()) : Target.FormattedValues[AttributeName];
                }
                else if (Target[AttributeName] is bool)
                {
                    // Note: Boolean values ignore the match value, they just use the attribute value itself as the condition
                    return Conditional.HasCondition ? Conditional.GetResult(Target.GetAttributeValue<bool>(AttributeName)) : Target.FormattedValues[AttributeName];
                }
                else if (Target[AttributeName] is DateTime)
                {
                    // If there is a format AND a condition, apply formatting first, then evaluate condition as a string
                    // If there is a condition without any format, evaluate condition as DateTime
                    return String.IsNullOrEmpty(StringFormatter) ? Conditional.GetResult(Target.GetAttributeValue<DateTime>(AttributeName)) : Conditional.GetResult(Target.GetAttributeValue<DateTime>(AttributeName).ToString(StringFormatter));
                }
                else if (Target[AttributeName] is Money)
                {
                    return Conditional.HasCondition ? Conditional.GetResult(Target.GetAttributeValue<Money>(AttributeName).Value) : Target.GetAttributeValue<Money>(AttributeName).Value.ToString(StringFormatter);
                }
                else if (Target[AttributeName] is int)
                {
                    return Conditional.HasCondition ? Conditional.GetResult(Target.GetAttributeValue<double>(AttributeName)) : Target.GetAttributeValue<double>(AttributeName).ToString(StringFormatter);
                }
                else if (Target[AttributeName] is decimal)
                {
                    return Conditional.HasCondition ? Conditional.GetResult(Target.GetAttributeValue<decimal>(AttributeName)) : Target.GetAttributeValue<decimal>(AttributeName).ToString(StringFormatter);
                }
                else if (Target[AttributeName] is double)
                {
                    return Conditional.HasCondition ? Conditional.GetResult(Target.GetAttributeValue<double>(AttributeName)) : Target.GetAttributeValue<double>(AttributeName).ToString(StringFormatter);
                }
                else if (Target[AttributeName] is string)
                {
                    return Conditional.GetResult(Target[AttributeName].ToString());
                }
            }
            else if (AttributeName.Equals("rand"))
            {
                string length = "";
                string stringStyle = "upper";
                int stringLength = 5;  // Seems like reasonable default

                if (StringFormatter.Contains('?'))
                {
                    length = StringFormatter.Split('?')[0];
                    stringStyle = StringFormatter.Split('?')[1].ToLower();
                }
                else
                {
                    length = StringFormatter;
                }

                if (!Int32.TryParse(length, out stringLength))
                {
                    stringLength = 5;
                }

                string stringValues = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                if (stringStyle == "mix")
                {
                    stringValues = stringValues + stringValues.ToLower();
                }
                else if (stringStyle == "lower")
                {
                    stringValues = stringValues.ToLower();
                }

                Random rnd = new Random();
                return String.Join("", Enumerable.Range(0, stringLength).Select(n => stringValues[rnd.Next(stringValues.Length)]));
            }

            return DefaultValue;
        }
开发者ID:BESDev,项目名称:Celedon-Autonumber-RTM,代码行数:83,代码来源:RuntimeParameter.cs

示例9: OpenView

 private void OpenView()
 {
     EnableControls(false);
     if (views == null || views.Count == 0)
     {
         LoadViews(OpenView);
         return;
     }
     var viewselector = new SelectViewDialog(this);
     viewselector.StartPosition = FormStartPosition.CenterParent;
     if (viewselector.ShowDialog() == DialogResult.OK)
     {
         view = viewselector.View;
         var fetchDoc = new XmlDocument();
         if (view.Contains("fetchxml"))
         {
             fetchDoc.LoadXml(view["fetchxml"].ToString());
             FetchUpdated(fetchDoc.OuterXml);
         }
     }
     EnableControls(true);
 }
开发者ID:rajyraman,项目名称:XrmToolBox.Plugins,代码行数:22,代码来源:MainControl.cs

示例10: GetAdministrator

        private string GetAdministrator(Entity e)
        {
            try
            {
                if (e.Contains("administratorid.domainname"))
                {
                    var er = e.GetAttributeValue<AliasedValue>("administratorid.domainname");

                    if (er != null && er.Value != null)
                    {
                        return er.Value as string;
                    }
                }

                return null;
            }
            catch
            {
                throw new Exception("Error encountered in GetAdministrator");
            }
        }
开发者ID:gotdibbs,项目名称:magician,代码行数:21,代码来源:ExportLogic.cs

示例11: GetParentEntity

        /// <summary>
        ///     Return the entity record which is configured as the logical parent of this records autonumber
        /// </summary>
        public Entity GetParentEntity(Entity entity, XrmAutonumber autonumber, IEnumerable<string> fields)
        {
            //Need to split the links to the parent and create a query which returns the parent record via the links
            if (!entity.Contains(autonumber.FirstLinkLookup))
                return null;

            //Create a query which traverses through the keys and entities we defined in our autonumber links
            var query = new QueryExpression();
            query.ColumnSet = XrmService.CreateColumnSet(fields);
            LinkEntity carry = null;
            //for each foreign key entity pairing work from last to first
            for (var i = autonumber.LinksToParent.LinkToParents.Count(); i > 0; i--)
            {
                var thisLink = autonumber.LinksToParent.LinkToParents.ElementAt(i - 1);
                //if this is the last item we need to create it as the type of entity we are returning
                if (i == autonumber.LinksToParent.LinkToParents.Count())
                    query.EntityName = thisLink.LinkTarget;
                //otherwise if this is not the last item we need to add a link from the previous type to this type
                else
                {
                    var previousPair = autonumber.LinksToParent.LinkToParents.ElementAt(i);
                    if (carry == null)
                        carry = query.AddLink(thisLink.LinkTarget, previousPair.LinkFieldTarget, previousPair.LinkFieldSource);
                    else
                        carry = carry.AddLink(thisLink.LinkTarget, previousPair.LinkFieldTarget, previousPair.LinkFieldSource);
                }
                //if this is the first item we need to add a filter on the first id with the value in the lookup from the record we are creating the autonumber for
                if (i == 1)
                {
                    var thisLookupId = entity.GetLookupGuid(thisLink.LinkFieldSource);
                    if (!thisLookupId.HasValue)
                        return null;
                    if (autonumber.LinksToParent.LinkToParents.Count() != 1)
                        carry.LinkCriteria.AddCondition(carry.LinkToEntityName + "id", ConditionOperator.Equal, thisLookupId.Value);
                    else
                        query.Criteria.AddCondition(query.EntityName + "id", ConditionOperator.Equal, thisLookupId.Value);
                }
            }
            //Run the query and if a result return it
            var parent = XrmService.RetrieveMultiple(query);
            if (parent.Entities.Count > 0)
                return parent.Entities[0];
            return null;
        }
开发者ID:josephmcmac,项目名称:JosephM.Xrm.Autonumber,代码行数:47,代码来源:AutonumberService.cs

示例12: When_A_Plugin_Is_Executed_Configurations_Can_Be_Used

        public void When_A_Plugin_Is_Executed_Configurations_Can_Be_Used()
        {
            var fakedContext = new XrmFakedContext();

            var guid1 = Guid.NewGuid();
            var target = new Entity("contact") { Id = guid1 };

            var inputParams = new ParameterCollection { new KeyValuePair<string, object>("Target", target) };

            var unsecureConfiguration = "Unsecure Configuration";
            var secureConfiguration = "Secure Configuration";

            //Execute our plugin against the selected target
            var plugCtx = fakedContext.GetDefaultPluginContext();
            plugCtx.InputParameters = inputParams;

            fakedContext.ExecutePluginWithConfigurations<ConfigurationPlugin>(plugCtx, unsecureConfiguration, secureConfiguration);

            Assert.True(target.Contains("unsecure"));
            Assert.True(target.Contains("secure"));
            Assert.Equal((string)target["unsecure"], unsecureConfiguration);
            Assert.Equal((string)target["secure"], secureConfiguration);
        }
开发者ID:ccellar,项目名称:fake-xrm-easy,代码行数:23,代码来源:FakeContextTestPlugins.cs

示例13: CreateRecordWithStatusIfAny

 private static void CreateRecordWithStatusIfAny(Entity entity, IOrganizationService service)
 {
     //if trying to set the state, save it, remove from the entity and save it for changing the status after the creation
     var savedStatusCode = -1;
     var savedStateCode = -1;
     if (entity.Contains("statecode") && entity.Contains("statuscode"))
     {
         savedStateCode = entity.Attributes["statecode"] is OptionSetValue ?
             entity.GetAttributeValue<OptionSetValue>("statecode").Value : -1;
         savedStatusCode = entity.Attributes["statuscode"] is OptionSetValue ?
             entity.GetAttributeValue<OptionSetValue>("statuscode").Value : -1;
         entity.Attributes.Remove("statecode");
         entity.Attributes.Remove("statuscode");
     }
     var entityId = service.Create(entity);
     if (savedStatusCode != -1 && savedStateCode != -1)
     {
         var changeStateToNewRecordRequest = new SetStateRequest
         {
             State = new OptionSetValue(savedStateCode),
             Status = new OptionSetValue(savedStatusCode),
             EntityMoniker = new EntityReference(entity.LogicalName, entityId)
         };
         service.Execute(changeStateToNewRecordRequest);
     }
 }
开发者ID:imranakram,项目名称:CrmChainsaw,代码行数:26,代码来源:ReferenceDataTransporter.cs

示例14: UpdateAttributes

 // This currently only supports ONE attribute being updated, can be expanded to set/touch several attributes in the future
 private void UpdateAttributes(bool onlychange, string entity, List<string> attributes, object value, Entity record, object currentvalue)
 {
     if (!onlychange || !ValuesEqual(value, currentvalue))
     {
         var updaterecord = new Entity(entity);
         updaterecord.Id = record.Id;
         foreach (var attribute in attributes)
         {
             updaterecord.Attributes.Add(attribute, value);
         }
         Service.Update(updaterecord);
         if (record.Contains(attributes[0]))
         {
             record[attributes[0]] = value;
         }
         else
         {
             record.Attributes.Add(attributes[0], value);
         }
     }
 }
开发者ID:rajyraman,项目名称:XrmToolBox.Plugins,代码行数:22,代码来源:MainControl.cs

示例15: GetIsUnderDefaultBusinessUnit

        private bool GetIsUnderDefaultBusinessUnit(Entity e)
        {
            try
            {
                if (e.Contains("businessunitid.parentbusinessunitid"))
                {
                    var er = e.GetAttributeValue<AliasedValue>("businessunitid.parentbusinessunitid");

                    if (er != null && er.Value != null)
                    {
                        return false;
                    }
                }

                return true;
            }
            catch
            {
                throw new Exception("Error encountered in GetIsUnderDefaultBusinessUnit");
            }
        }
开发者ID:gotdibbs,项目名称:magician,代码行数:21,代码来源:ExportLogic.cs


注:本文中的System.Entity.Contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。