This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi all, I'm using LS 2.2 and inheritance with constants for subclasses. I have a subclass for data plans defined as the following. </p>
<p> [Discriminator(Attribute = "ClassId", Value = ClassDiscriminator.FixedCharge)]
This works great for retreiving existing database entries from the DB. Lightspeed correctly instanciates the subclass, then populates the values. However, when I call Repository.Add() and pass it a new instance (EntityState = EntityState.New) of a FixedChargePlan, LS inserts a null into my "ClassId" column. According to the doc, "The discriminator refers purely to a column and is therefore not required to be present in your domain model.". I obviously didn't add it to my model, but if it's declared in the class attributes, why doesn't it get persisted? How do I get this value into the db when the object is persisted?
Thanks, Todd
|
|
|
That looks like it should work, and I'll investigate to see if I can reproduce the problem. In the meantime, if you add a _classId field to your base class, does that solve the problem? (You don't need to create a wrapper property, just a field, so it won't pollute your public API.) |
|
|
That fixed the issue. This seems to be a bit of a bug. I simply assign the value in the constructor for each subclass, otherwise it's not populated when the instance persists. |
|
|
Thanks for the additional info. It does sound like we have a bug around this and I will investigate it further. However, since it sounds like there is a simple (albeit slightly annoying) workaround, we will probably fix it only on the 3.0 branch, not on 2.2. Are you okay to live with the workaround? |
|
|
Hi Ivan, I just upgrade to 3 and this problem still exists in the latest release. In fact I get errors when instanciating the object from the database result set if the descriminator is not a property on my instance when loading occurs. With 2.2 I only received an error on persisting new entities. |
|
|
Hi Todd, We have repro'ed the issue here and applied a fix for 3.0 for the error you were getting on load. This will be available in the 20100224 nightly build.
Jeremy |
|