예제 #1
0
 public EntityBuilder SetValue <T>(T val)
 {
     this.EntityBuilder.Entity[AttributeMetadata.LogicalName] = val;
     if (AttributeMetadata.IsPrimaryId.GetValueOrDefault())
     {
         this.EntityBuilder.Entity.Id = AttributeTypeConverter.GetUniqueIdentifier(val);
     }
     return(this.EntityBuilder);
 }
예제 #2
0
            /// <summary>
            /// Set's the appropriate SDK value of the attribute
            /// </summary>
            /// <param name="value">Will be coerced to the correct sdk type if the type is not appropriate for the attributes underlying metadata.</param>
            /// <returns></returns>
            public EntityBuilder SetValueWithTypeCoersion(object value)
            {
                var meta = this.AttributeMetadata;

                if (value == null || value is DBNull)
                {
                    return(this.SetNull());
                }

                if (meta.AttributeType != null)
                {
                    switch (meta.AttributeType.Value)
                    {
                    case AttributeTypeCode.BigInt:
                        SetValue(AttributeTypeConverter.GetBigInt(value));
                        break;

                    case AttributeTypeCode.Boolean:
                        SetValue(AttributeTypeConverter.GetBoolean(value));
                        break;

                    case AttributeTypeCode.CalendarRules:
                        SetValue(AttributeTypeConverter.GetCalendarRules(value));
                        break;

                    case AttributeTypeCode.Customer:
                        SetValue(AttributeTypeConverter.GetCustomer(value));
                        break;

                    case AttributeTypeCode.DateTime:
                        SetValue(AttributeTypeConverter.GetDateTime(value));
                        break;

                    case AttributeTypeCode.Decimal:
                        SetValue(AttributeTypeConverter.GetDecimal(value));
                        break;

                    case AttributeTypeCode.Double:
                        SetValue(AttributeTypeConverter.GetDouble(value));
                        break;

                    case AttributeTypeCode.EntityName:
                        SetValue(AttributeTypeConverter.GetEntityName(value));
                        break;

                    case AttributeTypeCode.Integer:
                        SetValue(AttributeTypeConverter.GetInteger(value));
                        break;

                    case AttributeTypeCode.Lookup:
                        SetValue(AttributeTypeConverter.GetLookup(value));
                        break;

                    case AttributeTypeCode.ManagedProperty:
                        SetValue(AttributeTypeConverter.GetManagedProperty(value));
                        break;

                    case AttributeTypeCode.Memo:
                        SetValue(AttributeTypeConverter.GetMemo(value));
                        break;

                    case AttributeTypeCode.Money:
                        SetValue(AttributeTypeConverter.GetMoney(value));
                        break;

                    case AttributeTypeCode.Owner:
                        SetValue(AttributeTypeConverter.GetOwner(value));
                        break;

                    case AttributeTypeCode.PartyList:
                        SetValue(AttributeTypeConverter.GetPartyList(value));
                        break;

                    case AttributeTypeCode.Picklist:
                        SetValue(AttributeTypeConverter.GetPicklist(value));
                        break;

                    case AttributeTypeCode.State:
                        SetValue(AttributeTypeConverter.GetState(value));
                        break;

                    case AttributeTypeCode.Status:
                        SetValue(AttributeTypeConverter.GetStatus(value));
                        break;

                    case AttributeTypeCode.String:
                        SetValue(AttributeTypeConverter.GetString(value));
                        break;

                    case AttributeTypeCode.Uniqueidentifier:
                        SetValue(AttributeTypeConverter.GetUniqueIdentifier(value));
                        break;

                    case AttributeTypeCode.Virtual:
                        SetValue(AttributeTypeConverter.GetVirtual(value));
                        break;

                    default:
                        throw new NotSupportedException("attribute type: " + meta.AttributeType.ToString() + " is not supoorted.");
                    }
                }

                return(EntityBuilder);
            }