August 14, 2011 DO 4.4 VS 2010 SP1 VB.NET

The Visual Basic implementation of the Console sample application that comes with DataObjects.Net 4.4 includes the following code:

      Using session = myDomain.OpenSession()
      Using transactionScope = session.OpenTransaction()
          If session.Query.All(Of MyEntity)().Count() <> 1
              Throw New InvalidOperationException()
          End If
          If session.Query.All(Of MyEntity)().First().Text <> "Hello World!"
              Throw New InvalidOperationException()
          End If
          For Each myEntity In session.Query.All(Of MyEntity)()
              System.Console.WriteLine(myEntity.Text)
          Next
          transactionScope.Complete()
      End Using
  End Using

Even though the code runs as advertised, the following lines Throw an InvalidOperationException

          If session.Query.All(Of MyEntity)().First().Text <> "Hello World!"
              Throw New InvalidOperationException()
          End If

Actually I'm not sure this exception is actually thrown. For example it isn't trapped by a Try Catch block, but when single stepping through the code in the debugger the line

Throw New InvalidOperationException()

is reached in response to the test for an Entity with the "Hello World!" text, but NOT in the prior test for Count <> 1?

Does anyone know why?

Cheers, Mark

asked Aug 14 '11 at 01:08

Mark%20Century's gravatar image

Mark Century
20112

edited Aug 14 '11 at 01:43

Hello Mark,

Could you please check whether your database contains an instance of MyEntity with 'Text' column equal to "Hello World!"?

(Aug 14 '11 at 06:52) Dmitri Maximov Dmitri%20Maximov's gravatar image

One Answer:

Hi Dmitri, I'm just using the default memory database configured for the sample in app.config:

  <domain name="Default" upgradeMode="Recreate" connectionUrl="memory://localhost/DO40-             Tests" >
    <types>
      <add assembly="Project1" />
    </types>
  </domain>

Not sure how to inspect the Memory database.

Here is the output in the Immediate Window when stepping into this line:

Step into: Stepping over non-user code 'Xtensive.Orm.Session.Query.get' Step into: Stepping over non-user code 'Project1.Model.MyEntity.~Xtensive.Aspects.FactoryMethod' Step into: Stepping over non-user code 'Project1.Model.MyEntity.MyEntity' Step into: Stepping over non-user code 'Project1.Model.MyEntity.~Xtensive.Aspects.FactoryMethod' Step into: Stepping over non-user code 'Xtensive.Orm.Internals.Activator.CreateEntity' Step into: Stepping over non-user code 'Xtensive.Orm.EntityState.Entity.get' Step into: Stepping over non-user code 'Xtensive.Orm.Linq.Materialization.ItemMaterializationContext.Materialize' Step into: Stepping over non-user code 'Xtensive.Core.DelegateBindExtensions.Bind<object[],xtensive.tuples.tuple,xtensive.orm.linq.materialization.itemmaterializationcontext,project1.model.myentity>.AnonymousMethod9' Step into: Stepping over non-user code 'Xtensive.Orm.Linq.Materialization.MaterializationHelper.Materialize<project1.model.myentity>.AnonymousMethod3' Step into: Stepping over non-user code 'System.Linq.Enumerable.WhereSelectEnumerableIterator<xtensive.tuples.tuple,project1.model.myentity>.MoveNext' Step into: Stepping over non-user code 'Xtensive.Core.EnumerableExtensions.Batch<project1.model.myentity>.MoveNext' Step into: Stepping over non-user code 'Xtensive.Core.EnumerableExtensions.ApplyBeforeAndAfter<project1.model.myentity>.MoveNext' Step into: Stepping over non-user code 'System.Linq.Enumerable.SelectManyIterator<system.collections.generic.ienumerable<project1.model.myentity>,Project1.Model.MyEntity>.MoveNext' Step into: Stepping over non-user code 'System.Linq.Enumerable.First<project1.model.myentity>' Step into: Stepping over non-user code 'Xtensive.Core.DelegateBindExtensions.Bind<object[],system.collections.generic.ienumerable<xtensive.tuples.tuple>,Xtensive.Orm.Session,System.Collections.Generic.Dictionary<xtensive.parameters.parameter<xtensive.tuplstep into:="" stepping="" over="" non-user="" code="" 'xtensive.orm.linq.translatedquery<project1.model.myentity="">.Execute' Step into: Stepping over non-user code 'Xtensive.Orm.Linq.QueryProvider.Execute<project1.model.myentity>'

Since the program displays "Hello World!" correctly in the console after querying this memory database, and myEntity has a "Synchronized" persistence state, it appears that indeed an Entity was created and persisted. Also even though the debugger single steps into the "Throw New InvalidOperationException" line, control flow is not interrupted. Rather it merely steps back out and continues to the For Each enumeration, which correctly outputs the text.

So I'm guessing now that something is interferring with the normal function of the debugger and that an exception is not actually thrown.

Mark

answered Aug 14 '11 at 08:32

Mark%20Century's gravatar image

Mark Century
20112

Mark,

Thanks for the investigation. It seems that the issue is not connected to DataObjects.Net.

P.S. When speaking about the database check I presumed that you run the sample against MS SQL Server or similar.

(Aug 14 '11 at 08:36) Dmitri Maximov Dmitri%20Maximov's gravatar image

I'll try running this sample app against my local SQL Server Express and report back.

(Aug 14 '11 at 08:47) Mark Century Mark%20Century's gravatar image

I get exactly the same behavior when persisting to SQL Server Express. And yes I verified that an instance of myEntity had been created with a "Hello World!" text field.

You are suggesting that this isn't a DataObjects.Net issue ... have you tried to duplicate this behavior?

One last observation. If I set a breakpoint on the "Throw New ... " line it is NOT trapped. However if I break prior to this and single step you go into this line.

Whatever is happening it appears fairly benign so I'm pushing forward.

(Aug 14 '11 at 09:05) Mark Century Mark%20Century's gravatar image
1

BTW I just finished reading the entire help documentation for DataObjects.Net congratulations on what appears to be a very comprehensive and well thought out framework. I"m going to use it now to develop an initial application. Thanks.

(Aug 14 '11 at 09:09) Mark Century Mark%20Century's gravatar image

Mark,

Thanks a lot. In case you have any questions, you may ask here (on this forum) or write directly to support@x-tensive.com.

Happy development with DataObjects.Net!

(Aug 14 '11 at 09:12) Dmitri Maximov Dmitri%20Maximov'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