Good morning gents,
As you may be aware, we are undergoing a migration of a rather large application from EntityFramework to
DevForce.
This week we have experienced a new problem regarding the NULLO (Null Entity)
for an abstract class.
Let’s consider the
following classes declaration (one base and two derived):
public abstract class Color : IbEm.Entity{ /// <summary>Gets or sets the ID. </summary> [Key] [DataMember] [Bindable(true, BindingDirection.TwoWay)] [Editable(true)] [Display(Name="ID", AutoGenerateField=true)] [IbVal.RequiredValueVerifier( ErrorMessageResourceName="PEQ_LNContainer_ID")] public System.Guid ID { get { return PropertyMetadata.ID.GetValue(this); } set { PropertyMetadata.ID.SetValue(this, value); } } }
public class Red : Color {} public class Blue : Color {}
public class Car { // Data Properties public System.Nullable<System.Guid> ColorID;
// Navigation Properties public Color Color { get {...}; set {...}; } } |
Before getting to the painting chamber, a car does not have any color. Let’s consider the following test code:
Car aCar = new Car() {Color = null};Assert.IsTrue(aCar.Color == null); Assert.IsFalse(aCar.Color is Red); Assert.IsFalse(aCar.Color is Blue); Assert.IsTrue((aCar.Color as Red) == null); Assert.IsTrue((aCar.Color as Blue) == null); |
With EntityFramework:
- All tests are passing successfully.
With DevForce
- The comparison to null is successful because we implemented an override for the “==” operator to consider the EntityAspect.IsNullEntity.
- BUT the is and as keywords tests are sometimes passing, something not, depending on what NULLO instance was created during instanciation.
As no color were assigned to the car yet, all casts of the Color property (either to red or blue) should still return null as it is the case with EntityFramework.
My guess is that DevForce is instanciating NULLO of the abstract class by choosing one of the NULLO in the list of concrete classes and that, sometime it is choosing the NULLO of the Red type and sometime it is choosing the NULLO of the Blue type. This creates all sort of side effect in the production code.
Any idea on how to overcome this (other than testing the nullabilitty of the properties or rewritting all the production code and tests)?
Hope you follow