Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveRecord - IsLoaded not set true when query is executed #32

Closed
awbacker opened this issue Jul 9, 2009 · 5 comments
Closed

ActiveRecord - IsLoaded not set true when query is executed #32

awbacker opened this issue Jul 9, 2009 · 5 comments

Comments

@awbacker
Copy link

awbacker commented Jul 9, 2009

Executing a linq query casues the IsNew flag to get True, but the IsLoaded flag to be False.

I am not sure what that the isLoaded flag is intended to mean, but I take it that it refers to the object being loaded from the db. The generated class's Load() method doesn't get called, it all happens in subsonic.extensions.database.ToEnumerable<t> (which creates the type, then calls database.Load<t>), which never sets the _isLoaded flag.

Since <t> is IActiveRecord, should it be calling instance.Load(reader, false)?

@awbacker
Copy link
Author

awbacker commented Jul 9, 2009

Perhaps this should actually be a call to item.SetIsLoaded(true) inside the database.Load<t>() call?

@spookytooth
Copy link

I don't follow you - I need to repro this.

@robconery
Copy link
Collaborator

(that's me btw)

@awbacker
Copy link
Author

awbacker commented Jul 9, 2009

hehe :) it goes like this for me...

var list = (from p in data.products.all() where p.createdOn > now select p).ToList()
stack:
Extensions.Database.Load /t/
Extensions.Database.ToEnumerable /t/
....
Linq.Structure.DbQueryProvider.Execute
Linq.Structure.Query...
....
System.Linq.ToEnumerable()

The object is created in Database.ToEnumerable(), calling the default constructor which sets IsNew=true. The Database.Load() function then populates the object /t/. The only places in the object that set IsLoaded are the Load(reader,...) functions and SetIsLoaded(). Since the object didn't load itself (database.load did), and SetIsLoaded did not get called, the object is not marked that way. It also means that IsNew does not get reset to false.

I noticed this because it causes the IsDirty property to fail, since that reliese on _dirtyColumns which is not populated by the setter since _isLoaded is false.

@robconery
Copy link
Collaborator

Great - thank you! Fixed...

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants