Entity is out of sync.

Posts   
 
    
Posts: 72
Joined: 11-Aug-2006
# Posted on: 21-Sep-2006 06:14:11   

Hi There, I have read a lot of posts regarding this message online, but I can't figure out why. I think maybe I don't understand prefetch paths completely in relation to in-memory objects. I get the following error when I change part of the query ( specifically the shopping cart.rolename )

The entity is out of sync with its data in the database. Refetch this entity before using this in-memory instance. confused

So - I read the data once, change the predicate expression in the subpath , and read again and I get that error. I am doing no updating whatsover anywhere ( I even ran SQL profiler to check ) .

Any ideas? Here is the code that I am using in both cases - the only difference is.. VwSkudetailsFields.RoleName == ShoppingCart.RoleName << Rolename will have changed the second time around. It errors in the categoryMod.BindData(category) which is only reading one of the values into a string.

string categoryName = Request.QueryString["cname"];
CategoryEntity category = new CategoryEntity();
category.CategoryName = categoryName;
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
    RelationPredicateBucket filter = new RelationPredicateBucket();
    filter.PredicateExpression.Add(CategoryFields.CategoryName == categoryName);
    PrefetchPath2 prefetch = new PrefetchPath2((int)EntityType.CategoryEntity);
prefetch.AddCategoryEntity.PrefetchPathProductCollectionViaCategoryProduct).SubPath.Add(ProductEntity.PrefetchPathVwSkudetails,0, new PredicateExpression(VwSkudetailsFields.RoleName == ShoppingCart.RoleName));
   adapter.FetchEntityUsingUniqueConstraint(category,category.ConstructFilterForUCCategoryName(), prefetch);
                
}
categoryMod.BindData(category);
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Sep-2006 08:37:17   

I read the data once, change the predicate expression in the subpath , and read again and I get that error

Do you pass through the same piece of code when you "read again"?

What's the runtime Library version you are using? (right click on the "SD.LLBLGen.Pro.ORMSupportClasses.NETxx.dll" file select Properties, then go to the version tab, and there you will find the "File Version")

A side note: You don't use the filter you have constructed in the code you've posted.

Posts: 72
Joined: 11-Aug-2006
# Posted on: 21-Sep-2006 09:33:47   

Walaa wrote:

I read the data once, change the predicate expression in the subpath , and read again and I get that error

Do you pass through the same piece of code when you "read again"?

What's the runtime Library version you are using? (right click on the "SD.LLBLGen.Pro.ORMSupportClasses.NETxx.dll" file select Properties, then go to the version tab, and there you will find the "File Version")

A side note: You don't use the filter you have constructed in the code you've posted.

Yes exactly the same code is run both times.

The version is 2.0.0.60911

I'm not sure what you mean when you say the filter is not being used.
That is the only bit that changes.. i.e. it could read ( first read ) PredicateExpression(VwSkudetailsFields.RoleName == "Public")); (second read) PredicateExpression(VwSkudetailsFields.RoleName == "SpecialRole"));

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Sep-2006 09:57:18   

I was speaking about this:

RelationPredicateBucket filter = new RelationPredicateBucket();
filter.PredicateExpression.Add(CategoryFields.CategoryName == categoryName);

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 21-Sep-2006 10:13:26   

The read might result in no data being read from the db. When that happens the entity is outofsync as well (In adapter). Could you check for me if that's the case?

Also, when you say: read it again, if you don't use a context, you'll read it into a different instance. This is most of the time OK, but just in case you didn't know that simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Posts: 72
Joined: 11-Aug-2006
# Posted on: 21-Sep-2006 11:39:06   

Otis wrote:

The read might result in no data being read from the db. When that happens the entity is outofsync as well (In adapter). Could you check for me if that's the case?

Also, when you say: read it again, if you don't use a context, you'll read it into a different instance. This is most of the time OK, but just in case you didn't know that simple_smile

Yes you are correct in saying that is doesn't read all data from the database. ( checked SQL profiler ) On the second read, only the data for the category entity is read.. but no related entities.

There is no context being used FYI I am using ASP.NET, SQL Server.

The other interesting thing is that the 2 x database reads are in seperate postbacks.

The only other thing I can think of is that I have a couple of product entities in a session object ( Cart object ) - maybe that is interfering with it. [ update - flag that - I took the session objects out and it still errors ].

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Sep-2006 15:12:44   

So in the second fetch the filter used in the prefetchpath does not return any results for the related entities.

I think this can be solved if you checked the validity of the related entities before you use them in your code. (anything that access the related un-fetched entities...like databinding)

Posts: 72
Joined: 11-Aug-2006
# Posted on: 21-Sep-2006 17:47:44   

Walaa wrote:

So in the second fetch the filter used in the prefetchpath does not return any results for the related entities.

I think this can be solved if you checked the validity of the related entities before you use them in your code. (anything that access the related un-fetched entities...like databinding)

But why are they invalid? Both queries work if I run them first. It's the second time I run them that causes the problem and they are in different postbacks. I don't understand why there should be any connection between the 2 unless llblgenpro is holding some sort of state between postbacks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 22-Sep-2006 16:38:24   

martytheman wrote:

Otis wrote:

The read might result in no data being read from the db. When that happens the entity is outofsync as well (In adapter). Could you check for me if that's the case?

Also, when you say: read it again, if you don't use a context, you'll read it into a different instance. This is most of the time OK, but just in case you didn't know that simple_smile

Yes you are correct in saying that is doesn't read all data from the database. ( checked SQL profiler ) On the second read, only the data for the category entity is read.. but no related entities.

This only happens when the second time the category isn't found in the db, that is: based on the UC value specified. Because no category is found, the code won't proceed with fetching related entities, as there aren't any anyway (as the category isn't there).

Could you enable DQE tracing and see what the query looks like when it's send to the db and thus also what value exactly is send for the UC field in the filter?

Frans Bouma | Lead developer LLBLGen Pro
Posts: 72
Joined: 11-Aug-2006
# Posted on: 23-Sep-2006 01:20:09   

Otis wrote:

martytheman wrote:

Otis wrote:

The read might result in no data being read from the db. When that happens the entity is outofsync as well (In adapter). Could you check for me if that's the case?

Also, when you say: read it again, if you don't use a context, you'll read it into a different instance. This is most of the time OK, but just in case you didn't know that simple_smile

Yes you are correct in saying that is doesn't read all data from the database. ( checked SQL profiler ) On the second read, only the data for the category entity is read.. but no related entities.

This only happens when the second time the category isn't found in the db, that is: based on the UC value specified. Because no category is found, the code won't proceed with fetching related entities, as there aren't any anyway (as the category isn't there).

Could you enable DQE tracing and see what the query looks like when it's send to the db and thus also what value exactly is send for the UC field in the filter?

THANKS! for your help everyone. what was happenning was that we are using a URL rewriter that is changing on of the query strings for some reason.. so yes the category name wasn't being received. I guess I found the message "out of sync" a little confusing, maybe entity not foundmight be a better message. Anyway - I understand what is happenning now and I really appreciate your time and assistance smile