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; }
public ValidationContext(Object instance, Object propertyValue, StructuralProperty property = null) { Instance = instance; PropertyValue = propertyValue; Property = property; }
public ValidationContext(IStructuralObject so, StructuralProperty property, Object propertyValue) : this(so) { Property = property; PropertyValue = propertyValue; }
public EntityError Resolve(EntityManager em) { IsServerError = true; try { EntityType entityType = null; if (EntityTypeName != null) { var stName = TypeNameInfo.FromClrTypeName(EntityTypeName).ToClient(em.MetadataStore).StructuralTypeName; entityType = em.MetadataStore.GetEntityType(stName); var ek = new EntityKey(entityType, KeyValues); Entity = em.GetEntityByKey(ek); } if (entityType != null) { if (PropertyName != null) { Property = entityType.Properties.FirstOrDefault(p => p.NameOnServer == PropertyName); if (Property != null) { PropertyName = Property.Name; } } var vc = new ValidationContext(this.Entity); vc.Property = 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; }