private void ValidateValueMember(EntityRecord record, EntityMemberInfo member) { bool nullable = member.Flags.IsSet(EntityMemberFlags.Nullable); var value = record.GetValue(member); // Checking non-nullable fields; note that identity field for new records is initialized with temp value (in ValueBox) if (!nullable) { if (member.DataType == typeof(string)) { // Treat empty string as null if (string.IsNullOrEmpty((string)value)) { record.AddValidationError(ClientFaultCodes.ValueMissing, ClientFaultMessages.ValueMissing, new object[] { member.MemberName }, member.MemberName); } } else { if (value == null || value == DBNull.Value) { record.AddValidationError(ClientFaultCodes.ValueMissing, ClientFaultMessages.ValueMissing, new object[] { member.MemberName }, member.MemberName); } } } //Check string size if (member.DataType == typeof(string) && member.Size > 0) { var strValue = (string)value; if (strValue != null && strValue.Length > member.Size && member.Flags.IsSet(EntityMemberFlags.AutoValue)) { strValue = strValue.Substring(member.Size); record.SetValueDirect(member, strValue); } else { if (value != null && strValue.Length > member.Size) { record.AddValidationError(ClientFaultCodes.ValueTooLong, ClientFaultMessages.ValueTooLong, new object[] { member.MemberName, member.Size }, member.MemberName, strValue); } } } }
private void ValidateEntityRefMember(EntityRecord record, EntityMemberInfo member) { bool nullable = member.Flags.IsSet(EntityMemberFlags.Nullable); if (nullable) { return; //nothing to check } var isNull = record.KeyIsNull(member.ReferenceInfo.FromKey); if (isNull) { record.AddValidationError(ClientFaultCodes.ValueMissing, ClientFaultMessages.ValueMissing, new object[] { member.MemberName }, member.MemberName); } }