Lazy/Reference loading (was:Oracle EXTRACT tests operating on wrong datatype)

4 views
Skip to first unread message

Pablo Iñigo Blasco

unread,
Sep 14, 2008, 9:01:14 PM9/14/08
to dbl...@googlegroups.com
On Sun, Sep 14, 2008 at 5:30 PM, Pascal Craponne <pic...@gmail.com> wrote:
- A few core features are missing (outer joins, references loading, lazy loading)

On Sun, Sep 14, 2008 at 8:14 PM, Matthew Snyder <matthew....@gmail.com> wrote:
I was curious about the lazy/reference loading since I didn't see it
working. I just assumed I was doing something wrong. It'll be great to
help in any way I can.

Hi!

Regards lazy/reference loading we can distinguish two types:
1 - EntitySet lazy/reference loading
2 - EntityRef lazy/reference loading

The first one has been implemented during the summer (or at least a first approximation), until now it seems work properly, you can see it in ReadTest_EntitySet.SimpleMemberAccess01 and 02.

The second one was partially implemented during the summer but not committed, this night I have taken it up again and I have finished the work, it seems work fine (r882).

The following test work properly on mssql :-). It is a pleasure to navigate easily through entities:

  public void ReferenceLoading01()
        {
            var db = CreateDB();
            var order = db.Orders.First();
            //EntityRef
            Assert.IsNotNull(order.Employee);
        }

        [Test]
        public void ReferenceLoading02()
        {
            var db = CreateDB();
            var c = db.Customers.First();
            //EntitySet+EntityRef
            Assert.IsNotNull(c.Orders.First().Employee);
        }

        [Test]
        public void ReferenceLoading03()
        {
            var db = CreateDB();
            var employeeTerritory = db.EmployeeTerritories.First();
            //EntityRef+EntityRef+MemberAccess
            Assert.IsNotNull(employeeTerritory.Territory.Region.RegionID);
        }

Other comments:

· When an entity is created by the DataContext  EntitySet and EntityRefs properties are set or configured (but not retrieved from the database) .
· Maybe there will be problems with entities with multiples PKs. It should be interesting put some 'orders_details inserts' into our database-scripts and make more tests.

Suggestions and corrections are welcome.

Regards.

Matthew Snyder

unread,
Sep 15, 2008, 11:55:40 AM9/15/08
to DbLinq
Looks great so far! I did notice on Oracle and MySQL a decent amount
of queries now fail because, for example, the MS SQL Northwind.cs will
create a backing field for an association on, say,
nwind.Customer.Orders ([Association ... Storage = "_Orders" ...) and
many other mapping files don't have this yet, leading to an exception
when we try to set field to null.

Changing

let field = type.GetField(associationAttribute != null ?
associationAttribute.Storage : string.Empty, BindingFlags.NonPublic |
BindingFlags.Instance)

to

let field = type.GetField(associationAttribute != null ?
( associationAttribute.Storage ?? string.Empty ) : string.Empty,
BindingFlags.NonPublic | BindingFlags.Instance)

fixes this for now, but it's definitely a temporary solution. That
makes it work in MySQL, but not Oracle, yet.

- Matthew

On Sep 14, 9:01 pm, "Pablo Iñigo Blasco" <pibg...@gmail.com> wrote:
> On Sun, Sep 14, 2008 at 5:30 PM, Pascal Craponne <pic...@gmail.com> wrote:
> > - A few core features are missing (outer joins, references loading, lazy
> > loading)
>
> On Sun, Sep 14, 2008 at 8:14 PM, Matthew Snyder
> <matthew.c.sny...@gmail.com>wrote:

Pablo Iñigo Blasco

unread,
Sep 15, 2008, 12:19:15 PM9/15/08
to dbl...@googlegroups.com
Hi Mattew!


On Mon, Sep 15, 2008 at 5:55 PM, Matthew Snyder <Matthew....@gmail.com> wrote:
>
> Looks great so far! I did notice on Oracle and MySQL a decent amount
> of queries now fail because, for example, the MS SQL Northwind.cs will
> create a backing field for an association on, say,
> nwind.Customer.Orders ([Association ... Storage = "_Orders" ...) and
> many other mapping files don't have this yet, leading to an exception
> when we try to set field to null.

mmm that's strange because nwind.Customer.Orders is an EntitySet property. Look at the following piece of code:


> let field = type.GetField(associationAttribute != null ?
> associationAttribute.Storage : string.Empty, BindingFlags.NonPublic |
> BindingFlags.Instance)

Such piece of code is located in DataMapper.GetEntityRefAssociations(Type) and it isn't used for EntitySet properties (like nwind.Customers.Orders) but for EntityRef properties.

I mean, the Association.Storage info is only needed for EntityRef but not for EntitySets properties.
Look at the oracle-nwind.Order.Employee property, the association attribute contains the Storage field="_employee", so it should work fine even in oracle.

nwind.Customer.Order association attribute doesn't contains the Storage field, but it isn't needed by the DataMapper.GetEntitySetAssociations(Type) at least for the moment.

Nonetheless the change looks fine.

Regards.

Matthew Snyder

unread,
Sep 15, 2008, 12:52:15 PM9/15/08
to DbLinq
The way I was seeing it, GetEntityRefAssociations is iterating over
all public properties, including the ones that are EntitySets, and the
fact that a property like nwind.Customers.Orders has an
AssociationAttribute throws it off because we can't know if the
associated field is an EntityRef<> until we find its column name. And
since that isn't there for the EntitySet we're iterating over, that's
where the exception is coming from.

On Sep 15, 12:19 pm, "Pablo Iñigo Blasco" <pibg...@gmail.com> wrote:
> Hi Mattew!
>
> On Mon, Sep 15, 2008 at 5:55 PM, Matthew Snyder <Matthew.C.Sny...@gmail.com>

Pablo Iñigo Blasco

unread,
Sep 15, 2008, 12:59:18 PM9/15/08
to dbl...@googlegroups.com

On Mon, Sep 15, 2008 at 6:52 PM, Matthew Snyder <Matthew....@gmail.com> wrote:

The way I was seeing it, GetEntityRefAssociations is iterating over
all public properties, including the ones that are EntitySets, and the
fact that a property like nwind.Customers.Orders has an
AssociationAttribute throws it off because we can't know if the
associated field is an EntityRef<> until we find its column name. And
since that isn't there for the EntitySet we're iterating over, that's
where the exception is coming from.

Yeah, that's absolutely right. Excuse me. "What someone write is different to what someone think" ^^
But with your solution it seems to be solved. Why it's failing for Oracle and it is running fine for MySql?

Matthew Snyder

unread,
Sep 15, 2008, 1:17:33 PM9/15/08
to DbLinq
My mistake on that, I forgot to re-run my tests. For Oracle, the first
two ReferenceLoading tests are working, the last one isn't. So we're
definitely getting there! :-)

On Sep 15, 12:59 pm, "Pablo Iñigo Blasco" <pibg...@gmail.com> wrote:
> On Mon, Sep 15, 2008 at 6:52 PM, Matthew Snyder
> <Matthew.C.Sny...@gmail.com>wrote:

Matthew Snyder

unread,
Sep 15, 2008, 1:49:49 PM9/15/08
to DbLinq
Bam! All three tests work on Oracle. There were pieces of the
Northwind schema that weren't in create_Northwind_ora.sql. I guess
I'll put those additions and the change I made above into a commit?

Pablo Iñigo Blasco

unread,
Sep 15, 2008, 1:53:50 PM9/15/08
to dbl...@googlegroups.com
Yeah, but IMO the coherence in sqlscrptis must be a priority.
Then you have three choices:
- Change rest of scripts (mssql,postgree,mysql..), better but more work.
- Commit only the changes, and to modify the 3rd test to do it coherent with the data (if it is necessary changing the tables of such test).

After this, commit it! Thanks Mattew! :-)
--
Saludos. Pablo Iñigo Blasco .
Reply all
Reply to author
Forward
0 new messages