The problem: We have a set of different coupled objects, say, some entity and 1-4 linked ones. We need to have some kind of "rollback transaction" and operations log for operations made. For examle: Mark some time and object state(begin operation), edit 1 record in the main entity, and many records in the linked ones, then commit or rollback the whole operation. This operation can be really long(10min-some hours or more). The question: Can i achieve this with DisconnectedState? Can I get readable log from It?

Updated at 02.04.2010 8:02:09

One more question. How can I control, if entities go into the cache or not. More precisely, I want to separate the data I want to change(and keep it in the DS) and the data I just want to read. For example:

using (var session = Session.Open(domain))
                using (state.Attach(session))
                    using (var transactionScope = Transaction.Open())
                        using (state.Connect())
                            suppliers = Query.All<FilterEntity>().Prefetch(s => s.Sample).ToList();
                            products = Query.All<SampleEntity>().Prefetch(p => p.LinkedItem).ToList();

                            // I DONT need these entities in the cache
                            var sum = Query.All<SomeEntityWithHugeAmountOfDataAndNumberOfEntities>.Where(e => products.Select(p => p.Smth).Contains(e.Prop)).Sum();

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


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

asked Apr 01 '10 at 09:32

xumix's gravatar image


One Answer:

> Can i achieve this with DisconnectedState?

Yes. This scenario is one of its design goals.

> Can I get readable log from It?

Yes. DisconnectedState.Operations provides a sequence of all the logged operations. See the inheritance hierarchy of Operation type (all these classes are in Xtensive.Storage.Operations namespace) to get imagination of what's logged there.

You can also execute only a part of operations later (e.g. by filtering them) - just copy a part of them to your own OperationLog and replay it.

> I DONT need these entities in the cache

Currently there is no way to do this, but it seems a very reasonable requirement. I'll add it to an issue for DisconnectedState improvements based on running discussions.

> And even more) How can I see the old value of the object/field in the OperationLog? I want to use it in the auditing system.

There are no old values in operation log - its purpose is different (it doesn't need old values).

But you can get the old value while applying the changes - either by listening to Session.EntityChanging or similar events during replay operation, or by replaying the operations manually. See OperationLog.Replay method implementation - it is quite simple. The only complex part is that OperationContext constructor is internal, so you you'll need to use reflection to create its instance.

answered Apr 01 '10 at 17:11

Alex%20Yakunin's gravatar image

Alex Yakunin

And even more) How can I see the old value of the object/field in the OperationLog? I want to use it in the auditing system.

(Apr 01 '10 at 17:11) xumix xumix's gravatar image

About 1) it would be nice to have smth like: Query.All<someentitywithhugeamountofdataandnumberofentities>.NoCache() 2) Ok, thanks.

(Apr 01 '10 at 17:11) xumix xumix's gravatar image

Concerning .NoCache(): I'll think about this. Possibly, we will provide a construction with using (like for .Connect()) to deal with this in similar fashion.

(Apr 01 '10 at 17:11) Alex Yakunin Alex%20Yakunin'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


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



Asked: Apr 01 '10 at 09:32

Seen: 2,233 times

Last updated: Apr 01 '10 at 09:32

powered by OSQA