In some conditions ToArray throws exception

I see two problems:

  1. Index from base abstract class that not in hierarchy wasn't created in DB

  2. When index doesn't exist ToArray fails

Success when

  1. Add HierarchyRoot attribute on BaseEntity
  2. Add IndexAttribute on TestEntity
  3. Remove Indexed = false from Entity field (custom index also should be removed)

Sample:

using System;
using System.Linq;

using Xtensive.Orm;
using Xtensive.Orm.Configuration;

class Program
{
    static void Main(string[] args)
    {
        var dc = new DomainConfiguration("sqlserver://localhost/DO40-Tests");

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

        dc.UpgradeMode = DomainUpgradeMode.Recreate;
        var sessionConfiguration = new SessionConfiguration(SessionOptions.AutoActivation | SessionOptions.ServerProfile);

        using (var domain = Domain.Build(dc))
        {
            using (var session = domain.OpenSession(sessionConfiguration))
            using (session.Activate())
            using (var t = session.OpenTransaction())
            {
                var entity = new WithEntitySet { Name = "Test" };

                for (int i = 0; i < 250; i++)
                {
                    new TestEntity { Entity = entity, Name = "Test" };
                }

                t.Complete();
            }

            using (var session = domain.OpenSession(sessionConfiguration))
            using (session.Activate())
            using (var t = session.OpenTransaction())
            {
                Session.Current.Query.All<WithEntitySet>().First().List.ToArray();
            }
        }
    }
}

// [HierarchyRoot] with this - success
[Index("Entity", Clustered = true, Name = "Clustered")]
[Serializable]
public abstract class BaseEntity : Entity
{
    [Key]
    [Field(Nullable = false)]
    public Guid Id { get; private set; }

    // [Field] with this - success
    [Association(OnTargetRemove = OnRemoveAction.Cascade, OnOwnerRemove = OnRemoveAction.Clear)]
    [Field(Indexed = false)]
    public WithEntitySet Entity { get; set; }
}

// [Index("Entity", Clustered = true, Name = "Clustered")] with this - success
[HierarchyRoot]
public class TestEntity : BaseEntity
{
    [Key]
    [Field(Nullable = false)]
    public Guid Id { get; private set; }

    [Field(Nullable = false, Length = 400)]
    public string Name { get; set; }
}

[HierarchyRoot]
[Serializable]
public class WithEntitySet : Entity
{
    [Key]
    [Field(Nullable = false)]
    public Guid Id { get; private set; }

    [Field(Nullable = false, Length = 400)]
    public string Name { get; set; }

    [Field]
    [Association(PairTo = "Entity")]
    public EntitySet<TestEntity> List { get; set; }
}

Exception:

Object reference not set to an instance of an object.

at Xtensive.Orm.Rse.RecordSetHeader.CreateHeader(IndexInfo indexInfo)
at Xtensive.Orm.Rse.RecordSetHeader.GetHeader(IndexInfo indexInfo)
at Xtensive.Orm.Rse.RecordSetHeaderExtensions.GetRecordSetHeader(IndexInfo indexInfo)
at Xtensive.Orm.Rse.Providers.IndexProvider..ctor(IndexInfo index)
at Xtensive.Orm.Rse.IndexInfoExtensions.GetQuery(IndexInfo index)
at Xtensive.Orm.EntitySetBase.BuildEntitySetTypeState(Object key, EntitySetBase entitySet)
at Xtensive.Orm.EntitySetBase.<GetEntitySetTypeState>b__12(Object k)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Xtensive.Orm.EntitySetBase.GetEntitySetTypeState()
at Xtensive.Orm.EntitySetBase.EnsureCountIsLoaded()
at Xtensive.Orm.EntitySetBase.get_Count()
at Xtensive.Orm.EntitySet`1.System.Collections.Generic.ICollection<TItem>.get_Count()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)

asked Nov 25 '14 at 00:23

Anton%20Guschin's gravatar image

Anton Guschin
73303035

DO version 5.0.1

(Nov 25 '14 at 00:25) Anton Guschin Anton%20Guschin's gravatar image

One Answer:

Hi Anton

This is a bug of DO. We'll fix it next version.

The problem is that on making definitions step DO creates definition for custom index, but then DO removes BaseEntity because there is no hierarchy which contains this class and TestEntity doesn't inherit index.

answered Nov 26 '14 at 02:22

Alexey%20Kulakov's gravatar image

Alexey Kulakov
77225

DO 5.0.16 Index from base class (that not in hierarchy) created normally

But if field 'Entity' does not have any index, execution failed with same exception

(Oct 25 '17 at 07:58) Gushchin Anton Gushchin%20Anton's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA