Skip to content

Entity not persisted to the storage in the corner case #439

Description

@letarak

Hi there

DO 7.1.5

When entity created and SaveChanges not triggered and exception thrown on query translation

internal class Program
{
    private static void Main(string[] args)
    {
        var currentConnection =
            new SqlConnectionStringBuilder(DbHelper.ConnectionString());

        var dc = new DomainConfiguration("sqlserver", currentConnection.ToString());

        dc.Types.Register(typeof(TestEntity));

        dc.UpgradeMode = DomainUpgradeMode.Recreate;

        using var d = Domain.Build(dc);
        using var s = d.OpenSession();
        using var a = s.Activate();
        using var t = s.OpenTransaction();

        var item = new TestEntity(s, 123)
        {
            Name = "test"
        };

        // OK WHEN
        // s.SaveChanges();
        
        try
        {
            Expression<Func<TestEntity, bool>> expression = it => Query.All<TestEntity>()
                .Where(e => e.Name == it.Name)
                .Contains(it);

            expression.Compile().Invoke(null);
        }
        catch (Exception e)
        {
            // System.NullReferenceException in Xtensive.Orm.Providers.CommandFactory.GetParameterValue
            Console.WriteLine(e);
        }
                
        Assert.NotNull(item);
        Assert.AreEqual(1, Query.All<TestEntity>().Count(it => it.Id == item.Id));
    }

    [HierarchyRoot]
    public class TestEntity : Entity
    {
        public TestEntity(Session session, int id) 
            : base(session, id)
        {
        }

        [Key] [Field] public int Id { get; private set; }

        [Field] public string Name { get; set; }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions