New Posts New Posts RSS Feed: Cache is bypassed
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Cache is bypassed

 Post Reply Post Reply
Author
Frederic View Drop Down
Newbie
Newbie
Avatar

Joined: 09-Sep-2011
Location: Canada
Posts: 8
Post Options Post Options   Quote Frederic Quote  Post ReplyReply Direct Link To This Post Topic: Cache is bypassed
    Posted: 16-Sep-2011 at 8:14am
Hi Silvio,

This morning, I did the upgrade to version 6.1.2 of Devforce and you are right my problem has gone away both in my small sample application I sent you the other day as well as my main application.

I would consider the case closed. A thumbs up to you.

Good job, thanks

Frederic
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 15-Sep-2011 at 12:36pm
Hi Frederic,

I have tested and verified the issue in DevForce 6.0.9.

Also, I checked and this issue is no longer present in the latest version of DevForce (6.1.2)

Upgrading will resolve the problem.

Kind regards,
   Silvio.
Back to Top
Frederic View Drop Down
Newbie
Newbie
Avatar

Joined: 09-Sep-2011
Location: Canada
Posts: 8
Post Options Post Options   Quote Frederic Quote  Post ReplyReply Direct Link To This Post Posted: 13-Sep-2011 at 1:10pm
Hi Silvio,

as mentionned, here are the sample files:

Frederic
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 13-Sep-2011 at 12:44pm
Thanks for the update, Frederic.

I'll test it here and follow up.

Silvio.
Back to Top
Frederic View Drop Down
Newbie
Newbie
Avatar

Joined: 09-Sep-2011
Location: Canada
Posts: 8
Post Options Post Options   Quote Frederic Quote  Post ReplyReply Direct Link To This Post Posted: 13-Sep-2011 at 12:42pm
Thanks a lot Silvio to provide time to assist me,

Actually I did not mention the fact that in my sample I made a derivation of entity to produce the problem. At first, I thought it was not important to mention but I must be wrong.

I made changes to the model so that to get a derived entity as shown in the picture at the end of this post.

Anyway, this is the sample I have been using:

static void Main(string[] args)
{
NorthwindIBEntities manager = new NorthwindIBEntities(
shouldConnect: true,
dataSourceExtension: String.Empty,
entityServiceOption: IbEm.EntityServiceOption.UseLocalService,
compositionContextName: String.Empty);
IbEm.EntityQuery<Employee> employees = manager.GetQuery<Employee>();
IbEm.EntityQuery<Group> groups = manager.GetQuery<Group>();
Group u2 = groups.Where<Group>(gr => gr.Name == "U2").First<Group>();
employees = employees.Where(e => e.Group.Name == "U2") as IbEm.EntityQuery<Employee>;
Int32 employeeCount = employees.AsEnumerable<Employee>().Count();

Employee newEmployee = new Employee();
newEmployee.EmployeeID = 11;
newEmployee.LastName = "Hewson";
newEmployee.FirstName = "Paul David";
newEmployee.Title = "Sales Representative";
newEmployee.TitleOfCourtesy = "Mr.";
newEmployee.BirthDate = new DateTime(1960, 5, 10);
newEmployee.HireDate = new DateTime(2011, 9, 7);
newEmployee.Address = "Sunset Boulevard";
newEmployee.City = "Hollywood";
newEmployee.Region = "CA";
newEmployee.PostalCode = "22222";
newEmployee.Country = "USA";
newEmployee.HomePhone = "(222) 222-2222";
newEmployee.Extension = "222";
newEmployee.Notes = "Former singer of U2";
newEmployee.PhotoPath = "http://en.wikipedia.org/wiki/File:Bono_at_the_2009_Tribeca_Film_Festival.jpg";
newEmployee.ReportsToEmployeeID = 2;
newEmployee.RowVersion = 0;
newEmployee.Group = u2; 
manager.AddEntity(newEmployee);

Int32 newEmployeeCount = employees.AsEnumerable<Employee>().Count();
}

I can provide you with the exact code sample + the mdf file in the next post.

As a final note these are the modifications I made to the NorthwindIB model:


Thanks again for your dedication and time.

Frederic
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 12-Sep-2011 at 5:26pm
Hi Frederic,
 
I was not able to reproduce the issue here. The count value changed and the datasource was not hit the second time when executing the same query.
 
Here's my test (against NorthwindIB):
 
var mgr = new NorthwindIBEntities();
 
 
// Will hit datasource
var ordersCount = mgr.GetQuery<Order>().Where(ord => ord.Employee.FirstName == "Nancy Lynn").AsEnumerable<Order>().Count();
 
 
var newOrder = new Order();
newOrder.OrderDate = DateTime.Today;
newOrder.Employee = mgr.GetQuery<Employee>().Where(emp => emp.FirstName == "Nancy Lynn").First<Employee>();
mgr.AddEntity(newOrder);
 
 
// Will not hit datasource
var ordersCount2 = mgr.GetQuery<Order>().Where(ord => ord.Employee.FirstName == "Nancy Lynn").AsEnumerable<Order>().Count();
 
Have you by any chance modified DefaultQueryStrategy? (i.e. mgr.DefaultQueryStrategy)
 
Could you provide a simple solution reproducing the issue? (preferably against NorthwindIB)
 
Also, you will find interesting these articles from DevForce Resource Center:
 
 
Regards,
Silvio.


Edited by sbelini - 12-Sep-2011 at 5:28pm
Back to Top
Frederic View Drop Down
Newbie
Newbie
Avatar

Joined: 09-Sep-2011
Location: Canada
Posts: 8
Post Options Post Options   Quote Frederic Quote  Post ReplyReply Direct Link To This Post Posted: 09-Sep-2011 at 12:51pm
Good afternoon,

Before posting, I had a quick look to see if the question was already adressed but could not find the answer, still, I apologize if the issue was already discussed.

I'm using Devforce 2010 version 6.0.9.0 on SQL Server 2008 R2.

It seems that an EntityQuery is not using entities in the cache (but it uses the ones in the datastore) whenever a condition is made using a navigation property.

For instance, if I have an entity called Band and another called Member with members belonging to one band (one to many relationship), the following query:

Int32 membersCount = manager.GetQuery<Member>().Where(e => e.Band.Name == "U2").AsEnumerable<Member>().Count();

membersCount will show 3

Now add a new bass player to the band using:

Member newBassPlayer = new Member();
newBassPlayer.Name = "Adam Clayton";
newBassPlayer.Band = manager.GetQuery<Band>().Where(e => e.Name == "U2").First<Band>();
manager.AddEntity(newBassPlayer);

For now the new player is added to the cache and is not yet stored in the database.

Now, the member count still shows 3 and using SQL server profiler, I notice that the query is performed on the datastore instead of the cache as expected by using "AsEnumerable<Member>".
Int32 membersCount = manager.GetQuery<Member>().Where(e => e.Band.Name == "U2").AsEnumerable<Member>().Count();
  1. What is the best practise to force the query to be performed on the cache and not on the datastore?
  2. It seems that previous versions of Devforce could specify to include records from Navigation properties (using the Include method) but I seem not able to do that anymore?
  3. Can you point me to relevant documentation regarding the proper use of the cache or other best practices?

Thanks a lot for your support

Frederic

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down