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
|
I have a model that has a base table and several inherited tables from the base. The base table specifies a discriminator property and each of the inheriting tables sets the discriminator to a unique value. I then created a migration project and used the migration to create a database. When I tried to add one of the inheriting entities I got an error message: System.Data.SqlClient.SqlException: Invalid column name 'Discriminator' when I called SaveChanges. On further investigation the database table created by the migration did not contain a column for the discriminator hence the error above. I also reviewed the generated migration class and the call to AddTable does not include a Field entry for the discriminator. Please help.... :) |
|
|
As a side note I added the discriminator to the migration class manually and it now works. |
|
|
An additional side note. I added a column to 2 of the inheriting classes (there are 8 total inheriting classes). The column was named the same in both of the classes to which it was added. The create migration command added that column to the base table twice and caused a SQL Exception when creating the table. (FYI... I am using the same name in the two inheriting tables because the column has the same meaning to those two tables. I did not add it to the base table as the column would have no meaning to the other 6 inheritors.) |
|
|
Is it possible to send through a copy of your model? Id be suspicious that there is something in the model structure which is causing the issue here but its not clear if this is a bug or not. You can email it through to us at support at mindscape.co.nz.
|
|
|
I sent a sample. |
|
|
Thanks - we have this through and will be having a look into this.
|
|
|
There are 2 problems with the model; First you need to define the discriminator field as a property on the BaseClass if you want to use migrations to create it. We don't require the discriminator field to be an actual entity property in practice but that only works if you manually create the database field on the underlying table yourself. Second you have defined Property1 on two separate child entities which is why it is being included in the migrations twice. You can get away with the same property defined on two separate child entities but this will lead to problems for migrations and any queries where both child entities are in scope so it is not supported.
|
|