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
|
when I define a base and an inherited class, no discriminator column will be generated in the database. |
|
|
To be generated into the database, the discriminator needs to be declared as a property on the base class. This is so that we can determine the correct data type for the column. If you don't want it to appear as part of your class' API, you can set the property's Generation option to FieldOnly. |
|
|
Thank you for your reply. When doing so, I run into an exception "Invalid index xx for this SqlParameterCollection with Count=xx.". At the moment the only working way is creating the database field by hand an ommiting the property from the table definition in the model. But I think, that could not be the way it should be?! |
|
|
You're right, that's not the way it should be. Is it possible for you to post your .nhmodel file so we can try to reproduce and fix this for you? Thanks! |
|
|
I have appended the requested file. The relavant entity is "VERTRAG" with discriminator column "VertragTyp". Thank you for helping me! |
|
|
Hmm, your file is working okay for me. I did an Update Database from Model to create the 'initial' tables from your file, which worked fine. I then added a VertragTyp property of type string to the Vertrag entity, and did another Update Database from Model. This again worked fine and generated the following change log: -- Add column VertragTyp of type String to table Vertrag Is there any further info you can give me about what you were doing when you got the exception? Is there a stack trace associated with the exception? Are you able to reproduce the exception when starting from a blank database and if so could you let me know the exact steps you took to do so? Thanks! |
|
|
Correct, the generation works fine. But when it comes to saving the entity, the error occurs. When searching the web, this error often is found in combination with a problem when you define a one-to-many association and additionally define the key as a property. This is exactly the same what happens in case of the inheritance. Without the defined property the column VertragTyp (created by hand) is updated correctly. I hope I will not produce to much confusion! Thank you! |
|
|
Ah, right! (Sound of a lightbulb going on.) I've reproduced the problem and we've updated the build in the Visual Studio Gallery with a candidate fix (assuming you installed from the VS Gallery, go into Extension Manager and check the Updates tab -- it may take a few seconds to appear). What you'll need to do is add the VertragTyp property as previously recommended. But we will now recognise that it is the discriminator and map it accordingly. So you won't get the SqlParameterCollection error. However, because VertragTyp is mapped as a discriminator rather than a domain property, the actual CLR property will NOT get populated. You should therefore set the Generation option to MappingOnly so you don't get a misleading property with the wrong value. (If you forget to set Generation to MappingOnly, the designer will raise a warning to remind you.) Please let us know if you still run into problems after installing the update. And thanks for reporting the problem and helping us track it down. |
|