New Posts New Posts RSS Feed: NullEntity of derived entities of an abstract entity
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

NullEntity of derived entities of an abstract entity

 Post Reply Post Reply
Author
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Topic: NullEntity of derived entities of an abstract entity
    Posted: 17-Jan-2012 at 7:33pm
Hi Frederic,

This does sound like a bug. However, I'm having difficulty reproducing it here. Attached is my repro solution. Could you help add/modify the test to make it fail? I believe my model structure is the same as yours.

If it's different, you can just send your edmx to me and I'll do my repro with your model. You can use the customer support form, http://www.ideablade.com/technical-support/CustomerSupportRequestForm.aspx, to send the edmx and refer to this forum post.



Edited by DenisK - 17-Jan-2012 at 7:37pm
Back to Top
Frederic View Drop Down
Newbie
Newbie
Avatar

Joined: 09-Sep-2011
Location: Canada
Posts: 8
Post Options Post Options   Quote Frederic Quote  Post ReplyReply Direct Link To This Post Posted: 13-Jan-2012 at 8:11am
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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down