In some conditions ToArray throws exception
I see two problems:
-
Index from base abstract class that not in hierarchy wasn't created in DB
-
When index doesn't exist ToArray fails
Success when
- Add HierarchyRoot attribute on BaseEntity
- Add IndexAttribute on TestEntity
- 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 Guschin
73●30●30●35
DO version 5.0.1