See example:

using (var session = Session.Open(domain))
            {
                using (state.Attach(session))
                {
                    using (var transactionScope = Transaction.Open())
                    {
                        using (state.Connect())
                        {
var qwe = Query.All<User>().Select(u => new { u.Created }).ToList();
//Exception here
var aaa = Query.All<User>().ToList();
                        }

                        transactionScope.Complete();
                    }
                }
            }

Version of entity with key 'User, (07f0df2a-b55f-44be-bb9b-034a875bf0de)' differs from the expected one. at Xtensive.Storage.DisconnectedState.RegisterState(Key key, Tuple tuple, VersionInfo version, MergeMode mergeMode) at Xtensive.Storage.DisconnectedState.RegisterState(Key key, Tuple tuple) at Xtensive.Storage.Disconnected.DisconnectedSessionHandler.RegisterEntityState(Key key, Tuple tuple) at Xtensive.Storage.Linq.Materialization.ItemMaterializationContext.Materialize(Int32 entityIndex, Int32 typeIdIndex, TypeInfo type, Pair1[] entityColumns, Tuple tuple) at lambda_method(ExecutionScope , Object[] , Tuple , ItemMaterializationContext ) at System.DelegateBindExtensions.<>c__DisplayClassa4.<bind>b9(T2 arg2, T3 arg3) at Xtensive.Storage.Linq.Materialization.MaterializationHelper.<>cDisplayClass41.<Materialize>b__3(Tuple tuple) at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.EnumerableExtensions.<batch>d271.MoveNext() at System.EnumerableExtensions.<ApplyBeforeAndAfter>d__2f1.MoveNext() at Xtensive.Storage.TransactionalExtensions.<totransactional>d01.MoveNext() at System.Linq.Enumerable.<SelectManyIterator>d__142.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToListTSource at Core.Tests.MembershipTest.SomeMethod() in D:\Home\Docs\Visual Studio 2008\Projects\Platform\Core.Tests\MembershipTest.cs:line 93


Updated at 02.04.2010 11:46:16

var state = new DisconnectedState();

            using (var session = Session.Open(domain))
            {
                using (state.Attach(session))
                {
                    using (var transactionScope = Transaction.Open())
                    {
                        using (state.Connect())
                        {
                            //SomeMethod();
                            var doc = Query.All<FilterEntity>().Where(f => f.Integer == 1).Prefetch(s => s.ItemGroup).Single();
                            var qwe = Query.All<User>().Select(u => new { u.Created }).ToList();

                            var subs = doc.ItemGroup.Where(g => true).ToList();

                            foreach (var sub in subs)
                            {
                                sub.Name = "1111";
                            }

                            doc.ItemGroup.Add(new AnotherEntity(Guid.NewGuid()));
                            doc.ItemGroup.Add(new AnotherEntity(Guid.NewGuid()));
                            doc.ItemGroup.Add(new AnotherEntity(Guid.NewGuid()));

                            var uuu = Query.All<User>().Select(u => new { u.Created }).OrderBy(a => a.Created).First();
                        }

                        var fe = new FilterEntity(Guid.NewGuid()) { Date = DateTime.Now, Integer = 123 };
                        //var ss = Query.All<FilterEntity>().Where(f => f.NullableGuid.HasValue).Single();
                        fe.Integer = 2222;

                        transactionScope.Complete();
                    }
                }
            }

            using (var session = Session.Open(domain))
            {
                using (state.Attach(session))
                {
                    using (var transactionScope = Transaction.Open())
                    {
                        using (state.Connect())
                        {
                            // Exception here
                            var doc = Query.All<FilterEntity>().Where(f => f.Integer == 1).Prefetch(s => s.ItemGroup).Single();

                            var subs = doc.ItemGroup.Where(g => true).ToList();

                            foreach (var sub in subs)
                            {
                                sub.Name = "22222";
                            }
                        }

                        transactionScope.Complete();
                    }
                }

                state.ApplyChanges();
            }

More exceptions here

Xtensive.Storage.VersionConflictException : Version of entity with key 'AnotherEntity, (0df4b47f-e104-42cf-adce-85da7a5e80c4)' differs from the expected one. at Xtensive.Storage.DisconnectedState.RegisterState(Key key, Tuple tuple, VersionInfo version, MergeMode mergeMode) at Xtensive.Storage.DisconnectedState.RegisterState(Key key, Tuple tuple) at Xtensive.Storage.Disconnected.DisconnectedSessionHandler.RegisterEntityState(Key key, Tuple tuple) at Xtensive.Storage.Internals.Prefetch.EntitySetTask.UpdateCache() at Xtensive.Storage.Internals.Prefetch.Fetcher.UpdateCacheFromAllEntitySetTasks(IEnumerable1 containers) at Xtensive.Storage.Internals.Prefetch.Fetcher.ExecuteTasks(IEnumerable1 containers, Boolean skipPersist) at Xtensive.Storage.Internals.Prefetch.PrefetchManager.ExecuteTasks(Boolean skipPersist) at Xtensive.Storage.Providers.SessionHandler.ExecutePrefetchTasks(Boolean skipPersist) at Xtensive.Storage.Internals.ChainingSessionHandler.ExecutePrefetchTasks(Boolean skipPersist) at Xtensive.Storage.Internals.Prefetch.RootElementsPrefetcher1.<GetEnumerator>d__0.MoveNext() at System.Linq.Enumerable.Single(IEnumerable1 source) at Core.Tests.MembershipTest.DsTest() in MembershipTest.cs: line 112


Updated at 02.04.2010 12:45:11

> Have a look at the first example. There are sequential Query.All() calls. No data is being modified. But it isn't clear if DisconnectedState is empty before this operation. Is it? It was empty, trust me :)

This thread was imported from our support forum. The original discussion may contain more detailed answer.

asked Apr 02 '10 at 10:48

xumix's gravatar image

xumix
425757682


One Answer:

Most likely, this happens because a new data is merged into DisconnectedState on query\prefetch, but versions there differ from the already cached ones (i.e. you merge changed entities).

Default merge behavior is controlled by DisconnectedState.MergeMode property.


Err... Forgot to add: most of errors related to this issue were in test code. But it identified few problems in DO4 as well.

See the following commit messages for details:

answered Apr 02 '10 at 12:14

Alex%20Yakunin's gravatar image

Alex Yakunin
29714412

> Have a look at the first example. There are sequential Query.All() calls. No data is being modified.

But it isn't clear if DisconnectedState is empty before this operation. Is it?

(Apr 02 '10 at 12:14) Alex Yakunin Alex%20Yakunin's gravatar image

Than it's a bug. We'll try to investigate it on the beginning of the next week.

What else could help: dump of two VersionInfos that differ there.

(Apr 02 '10 at 12:14) Alex Yakunin Alex%20Yakunin's gravatar image

I've send you code for this and other bugs. PoC for this bug is located in > private void SomeMethod() in MembershipTests

(Apr 02 '10 at 12:14) xumix xumix's gravatar image

Fixed. But after today's modifications about 40 new tests fail (likely, something wrong in LINQ translator), so please wait with updates for tomorrow.

(Apr 02 '10 at 12:14) Alex Yakunin Alex%20Yakunin's gravatar image

Have a look at the first example. There are sequential Query.All() calls. No data is being modified.

At the second one, I've modified entities in the DS, but not in the DB. And so MergeMode is usefull, thanks!

(Apr 02 '10 at 12:14) xumix xumix'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

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×573

Asked: Apr 02 '10 at 10:48

Seen: 2,151 times

Last updated: Apr 02 '10 at 10:48

powered by OSQA