I'm trying to get my validation on the run since hours. I want to use the RuleObjectExists Rule to detect if there are any objects in my db that contain the given value. (It's an order number duplicate check.)
I'm always getting a "Object reference not set to an instance of an object." exception. So I tried the code that is availlable in the docu. (Department at CustomMessageTemplate Property) Unfortunately I got the same exception:
An exception occurs while validating an object:
Exception: 'Object reference not set to an instance of an object.'
Rule Id: 'DevExpress.Persistent.Validation.RuleObjectExists_Titan.Module.Web.BusinessClasses.Department'
Rule Type: 'DevExpress.Persistent.Validation.RuleObjectExists'
Target Object: 'Titan.Module.Web.BusinessClasses.Department(00000000-0000-0000-0000-000000000000)'
My code:
[DefaultClassOptions]
[RuleObjectExists("",DefaultContexts.Save,"Office=205",InvertResult = true,
CriteriaEvaluationBehavior=PersistentCriteriaEvaluationBehavior.BeforeTransaction,
MessageTemplateMustExist = "The objects that satisfy the … criteria must not exist")]
public class Department : BaseObject
{
public Department(Session session) : base(session) { }
private string office;
public string Office
{
get { return office; }
set { SetPropertyValue("Office", ref office, value); }
}
}
Steps to Reproduce:
- Start Application
- Create New Department with Number 1
- Create New Department with Number 205
- Create New Department with Number 205
Actual Results:
An exception occurs while validating an object:
Exception: 'Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.'
Rule Id: 'DevExpress.Persistent.Validation.RuleObjectExists_tbr_validationtest.Module.Department'
Rule Type: 'DevExpress.Persistent.Validation.RuleObjectExists'
Target Object: 'tbr_validationtest.Module.Department(00000000-0000-0000-0000-000000000000)'
Expected Results:
Normal Rule Behaviour
Hello Torsten,
This bug is fixed in the next version of the suite. To avoid this exception in the current version, you can decorate your class with the DefaultProperty attribute:
[DefaultProperty("Office")] public class Department : BaseObject { ...
Alternatively, you can just add the 'Name' property to your class, so that this property is used as the default one:
public class Department : BaseObject { ... public string Name { get { return "Office# " + Office; } } }
Thanks,
Constantin