Hi.
I have entity that had moved from one namespace to another, name and structure of entity don't changed.
Problem occurs when solution run in PerformSafely mode.
First of all, I don't see Unsafe action, but solution throwed ReferentialConstraintViolation.
I was disappointed, when see that I lost data in DB.
Created a test project.
Bug repeated.
Test project:
namespace ConsoleApplication1
{
using Xtensive.Orm;
using Xtensive.Orm.Configuration;
class Program
{
static void Main(string[] args)
{
var cfg = new DomainConfiguration("sqlserver", "Data Source=localhost; Initial Catalog=do40-tests; Integrated Security=True;")
{
UpgradeMode = DomainUpgradeMode.Recreate,
ValidationMode = ValidationMode.OnDemand,
NamingConvention = new NamingConvention { NamingRules = NamingRules.UnderscoreDots }
};
cfg.Sessions.Add(new SessionConfiguration("Default")
{
BatchSize = 25,
DefaultIsolationLevel = SessionConfiguration.DefaultDefaultIsolationLevel,
CacheSize = 1000,
Options = SessionOptions.Default | SessionOptions.AutoTransactionOpenMode | SessionOptions.AutoTransactionSuppressMode
});
cfg.Types.Register(typeof(Program).Assembly);
var domain = Domain.Build(cfg);
var s = domain.OpenSession();
s.Activate();
// For recreate
using (var tr = s.OpenTransaction())
{
var link = new EntityB { TestField = "EntityB" };
new EntityA { TestField = "EntityA", TestLink = link };
tr.Complete();
}
}
}
[HierarchyRoot]
public class BaseEntity : Entity
{
[Field, Key]
public int Id { get; private set; }
}
/// <summary>
/// First entity
/// </summary>
[HierarchyRoot]
public class EntityA : Entity
{
[Field, Key]
public int Id { get; private set; }
/// <summary>
/// TestField
/// </summary>
[Field]
public string TestField { get; set; }
/// <summary>
/// TestLink
/// </summary>
[Field(Nullable = false)]
public EntityB TestLink { get; set; }
}
}
EntityB:
namespace ConsoleApplication1
{
using Xtensive.Orm;
/// <summary>
/// Second entity
/// </summary>
[HierarchyRoot]
public class EntityB : Entity
{
[Field, Key]
public int Id { get; private set; }
/// <summary>
/// TestField
/// </summary>
[Field]
public string TestField { get; set; }
}
}
Run solution.
Now change namespace for EntityB, add using to main file and set UpgradeMode = DomainUpgradeMode.PerformSafely
Run solution.
Exception:
SQL error occured.
Storage error details 'Entity: EntityB; Field: Id (FieldInfo);'
SQL error details 'Type: ReferentialConstraintViolation; Database: DO40-Tests; Table: EntityB; Column: Id; Constraint: FK_EntityA_TestLink_EntityB;'
Query 'ALTER TABLE [dbo].[EntityA] ADD CONSTRAINT [FK_EntityA_TestLink_EntityB] FOREIGN KEY ([TestLink_Id]) REFERENCES [dbo].[EntityB] ([Id]);'
Original message 'The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_EntityA_TestLink_EntityB". The conflict occurred in database "DO40-Tests", table "dbo.EntityB", column 'Id'.'
Go to DB and check data in table EntityB, it's empty!
However, adding RenameTypeHint fix situation, but i think erase data without warning it's huge bug!
DataObjects.Net v4.4.2
Greetings, Anton.
I'll check this, thanks for the complete and well designed bug report.
BTW, does usage of
NamingRules.UnderscoreDots
influence somehow on the behavior?Yes. If remove NamingConvention from cfg initialization, then the test project run without errors.
Thanks, that's important.