Beispiel #1
0
        public EntityError Resolve(EntityManager em)
        {
            IsServerError = true;
            try {
                EntityType entityType = null;
                if (EntityTypeName != null)
                {
                    var stName = StructuralType.ClrTypeNameToStructuralTypeName(EntityTypeName);
                    entityType = MetadataStore.Instance.GetEntityType(stName);
                    var ek = new EntityKey(entityType, KeyValues);
                    Entity = em.FindEntityByKey(ek);
                }

                if (PropertyName != null)
                {
                    PropertyName = MetadataStore.Instance.NamingConvention.ServerPropertyNameToClient(PropertyName);
                }
                if (Entity != null)
                {
                    Property = entityType.GetProperty(PropertyName);
                    var vc = new ValidationContext(this.Entity);
                    vc.Property = this.Property;
                    var veKey = (ErrorName ?? ErrorMessage) + (PropertyName ?? "");
                    var ve    = new ValidationError(null, vc, ErrorMessage, veKey);
                    ve.IsServerError = true;
                    this.Entity.EntityAspect.ValidationErrors.Add(ve);
                }
            } catch (Exception e) {
                ErrorMessage = (ErrorMessage ?? "") + ":  Unable to Resolve this error: " + e.Message;
            }
            return(this);
        }
Beispiel #2
0
        internal void UpdateClientServerFkNames(StructuralProperty property)
        {
            // TODO: add check for name roundtriping ( to see if ok)
            var nc      = MetadataStore.NamingConvention;
            var navProp = property as NavigationProperty;

            if (navProp != null)
            {
                if (navProp._foreignKeyNames.Count > 0)
                {
                    navProp._foreignKeyNamesOnServer = navProp._foreignKeyNames.Select(fkn => nc.Test(fkn, true)).ToSafeList();
                }
                else
                {
                    navProp._foreignKeyNames = navProp._foreignKeyNamesOnServer.Select(fkn => nc.Test(fkn, false)).ToSafeList();
                }

                if (navProp._invForeignKeyNames.Count > 0)
                {
                    navProp._invForeignKeyNamesOnServer = navProp._invForeignKeyNames.Select(fkn => nc.Test(fkn, true)).ToSafeList();
                }
                else
                {
                    navProp._invForeignKeyNames = navProp._invForeignKeyNamesOnServer.Select(fkn => nc.Test(fkn, false)).ToSafeList();
                }
            }
        }
 public StructuralProperty(StructuralProperty prop)
 {
     this.Name         = prop.Name;
     this.NameOnServer = prop.NameOnServer;
     this.Custom       = prop.Custom;
     this.IsInherited  = prop.IsInherited;
     this.IsScalar     = prop.IsScalar;
     this.IsUnmapped   = prop.IsUnmapped;
     this.Validators   = new ValidatorCollection(prop.Validators);
 }
Beispiel #4
0
 public StructuralProperty(StructuralProperty prop)
 {
     this.Name            = prop.Name;
     this.NameOnServer    = prop.NameOnServer;
     this.Custom          = prop.Custom;
     this.IsInherited     = prop.IsInherited;
     this.IsScalar        = prop.IsScalar;
     this.IsUnmapped      = prop.IsUnmapped;
     this.ValidationRules = prop.ValidationRules.ToList();
 }
Beispiel #5
0
        internal void UpdateClientServerName(StructuralProperty property)
        {
            var nc = MetadataStore.NamingConvention;

            if (!String.IsNullOrEmpty(property.Name))
            {
                property.NameOnServer = nc.Test(property.Name, true);
            }
            else
            {
                property.Name = nc.Test(property.NameOnServer, false);
            }
        }
Beispiel #6
0
 public StructuralProperty AddProperty(StructuralProperty prop)
 {
     // TODO: check that property is not already on this type
     // and that it isn't also on some other type.
     if (prop.IsDataProperty)
     {
         AddDataProperty((DataProperty)prop);
     }
     else
     {
         AddNavigationProperty((NavigationProperty)prop);
     }
     return(prop);
 }
Beispiel #7
0
        // called internally by property set logic
        internal IEnumerable <ValidationError> ValidateProperty(StructuralProperty prop, Object value)
        {
            IEnumerable <ValidationError> errors = null;
            var co = value as IComplexObject;

            if (co != null)
            {
                errors = co.ComplexAspect.Validate();
            }
            var vc         = new ValidationContext(this.StructuralObject, prop, value);
            var itemErrors = prop.Validators.Select(vr => ValidateCore(vr, vc)).Where(ve => ve != null);

            return(errors == null?itemErrors.ToList() : errors.Concat(itemErrors).ToList());
        }
Beispiel #8
0
 public T GetValue <T>(StructuralProperty prop)
 {
     return((T)GetRawValue(prop.Name));
 }
Beispiel #9
0
 public Object GetValue(StructuralProperty prop)
 {
     return(GetValue(prop.Name));
 }
Beispiel #10
0
 public ValidationContext(Object instance, Object propertyValue, StructuralProperty property = null)
 {
     Instance      = instance;
     PropertyValue = propertyValue;
     Property      = property;
 }
Beispiel #11
0
 public ValidationContext(IStructuralObject so, StructuralProperty property, Object propertyValue)
     : this(so) {
     Property      = property;
     PropertyValue = propertyValue;
 }
Beispiel #12
0
        public IEnumerable <ValidationError> ValidateProperty(StructuralProperty prop)
        {
            var value = this.GetValue(prop);

            return(ValidateProperty(prop, value));
        }