0
Fixed

An attempt to call FirstOrDefault on an empty entity repository using a field name results in a System.InvalidOperationException exception.

Shane Day (Chief Technology Officer) 14 years ago updated by anonymous 9 years ago 5

The following test:

        [Test]
        public void FirstOrDefaultWithNoDataTest()
        {
            using (var entityContext = CreateAndPrepareContext(PartitionId))
            {
               var firstItem = entityContext.Entities.FirstOrDefault(item => item.GetValueOrDefault<StringValue>(CreateEntityKey("NotThere")) == "Hello");

               Assert.IsNull(firstItem);
            }
        }

fails with the following exception:

System.InvalidOperationException : Sequence contains no elements

This fault should be corrected, and the above unit test included in the KnownEntityRepositoryTestFixtureBase test fixture.

The following works as a work around:

   [Test]
        public void FirstOrDefaultWithNoDataTest()
        {
            using (var entityContext = CreateAndPrepareContext(PartitionId))
            {
                var entities = entityContext.Entities;
                var firstItem = entities.Any()
                                    ? entities.FirstOrDefault(
                                        item =>
                                        item.GetValueOrDefault<StringValue>(CreateEntityKey("NotThere")) == "Hello")
                                    : default(TEntity);

               Assert.IsNull(firstItem);
            }
        }

Reassigned due to new project ownership.

Reassigned due to change in project ownership.

Tony, can you please confirm that this has been resolved in a recent check in.

Thanks.

The FirstOrDefaultWithNoDataTest passed.