How can we do that?
//Source class
[Serializable]
[HierarchyRoot]
public class Client : Entity
{
[Field, Key]
public int Id { get; set; }
[Field]
public string Name { get; set; }
[...]
[Field]
public DateTime RegistrationDate { get; private set; }
[Field]
public DateTime BirthDate { get; set; }
[...]
}
//source class, that uses Client
[HierarchyRoot()]
[Serializable]
public class ProductCheckAction : Entity
{
[Field, Key]
public int Id { get; set; }
[...]
[Field]
public ProductCheckFields Fields { get; set; }
[...]
}
public class ProductCheckFields : Structure
{
[Field]
public Client Client { get; set; }
[...]
}
===
//new Superclass
[Serializable]
[HierarchyRoot(InheritanceSchema = InheritanceSchema.ConcreteTable)]
public abstract class Contractor : Entity
{
[Field, Key]
public int Id { get; set; }
[Field]
public string Name { get; set; }
}
//modified Client class
[Serializable]
public class Client : Contractor
{
[Field]
public DateTime RegistrationDate { get; private set; }
[Field]
public DateTime BirthDate { get; set; }
[...]
}
===
===
//upgdade hints
hints.Add(new MoveFieldHint(typeof (Client), "Id", typeof (Contractor)));
hints.Add(new MoveFieldHint(typeof(Client), "Name", typeof(Contractor)));
===
But DO delete all clients at first, then we get error:
Xtensive.Orm.ReferentialConstraintViolationException: SQL error occured.
Storage error details 'Entity: Client; Field: Id (FieldInfo);'
ALTER TABLE [dbo].[ProductCheckAction] ADD CONSTRAINT [FK_ProductCheckAction_Fields.Client_Client] FOREIGN KEY ([Fields.Client]) REFERENCES [dbo].[Client] ([Id]);
Original message 'The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_ProductCheckAction_Fields.Client_Client". The conflict occurred in database "shop", table "dbo.Client", column 'Id'.' ---> System.Data.SqlClient.SqlException: The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_ProductCheckAction_Fields.Client_Client". The conflict occurred in database "shop", table "dbo.Client", column 'Id'.
update:
There is similar error in some cases (for example, when simply add one reference) and doing PerformSafely:
UPDATE [dbo].[Debenture] SET [Supplier.Id] = DEFAULT WHERE EXISTS (SELECT [aProductSupplier].[Id] FROM [dbo].[ProductSupplier] [aProductSupplier] WHERE ([aProductSupplier].[Id] = [Debenture].[Supplier.Id]));
DELETE FROM [dbo].[ProductSupplier];'
Original message 'The DELETE statement conflicted with the REFERENCE constraint "FK_PrimaryIncomingWaybillAction_Fields.Supplier_ProductSupplier". The conflict occurred in database "Drezex_B_Major", table "dbo.PrimaryIncomingWaybillAction", column 'Fields.Supplier'.
The statement has been terminated.'
DO deletes everything from ProductSupplier and leaves database broken.
Very strange: why PerformSafely makes queries that can DELETE all data from some table?
I think, it is not safely action :)
asked
Apr 20 '12 at 05:44
Ness
155●23●23●28
I've updated post with some strange PeformSafely action that is similar to main error.