Does linqConnect try to retrieve an object from the identity cache before executing a query in the database?
Link2sql has that possibility. http://msdn.microsoft.com/en-us/library ... 10%29.aspx
I'v tried to get the same behaviour with linqConnect, but it seems that linqConnect allways executes a query in the databese.
Retrieving Objects from the Identity Cache
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
Re: Retrieving Objects from the Identity Cache
LinqConnect should work in the very same way as it is described in the provided article: if you are querying for a single entity by its primary key, LinqConnect searches for it in the entity cache at first. However, if there is no such entity in the cache, it has to query the database.
For example, consider the following code:
If you are observing some other behaviour, please describe the situation in more details.
For example, consider the following code:
Code: Select all
MyDataContext context = new MyDataContext()
{ Log = Console.Out };
// Since the cache is empty, we query the database at this point.
Dept first = context.Depts
.OrderBy(d => d.Deptno)
.First();
// No SQL is executed now, because the entity with the smallest key is already cached.
Dept first1 = context.Depts
.Where(d => d.Deptno == first.Deptno)
.SingleOrDefault();
// The cache isn't empty, but no entity with the specified key was found.
// Hence has to search for it in the database.
Dept second = context.Depts
.Where(d => d.Deptno == first.Deptno + 10)
.SingleOrDefault();
Re: Retrieving Objects from the Identity Cache
I've put a query directly in SigleOrDefault
and it doesn't work, but your variant works pretty well.
Also it would be great if you fix another annoying bug. It is impossible to retrieve an object from the Identity Cache if type of the primary key is short or byte. It happens becouse of a typecast that C# compiller add to expression. Lets pretend that Deptno is short. C# compiller automatically convert lamdla d => d.Deptno == first.Deptno to d=> (int)d.Deptno == (int)first.Deptno This case isn't processed correctly neither linq2sql nor linqconnect
Thanks a lot
Code: Select all
Dept first1 = context.Depts
.SingleOrDefault(d => d.Deptno == first.Deptno);
Also it would be great if you fix another annoying bug. It is impossible to retrieve an object from the Identity Cache if type of the primary key is short or byte. It happens becouse of a typecast that C# compiller add to expression. Lets pretend that Deptno is short. C# compiller automatically convert lamdla d => d.Deptno == first.Deptno to d=> (int)d.Deptno == (int)first.Deptno This case isn't processed correctly neither linq2sql nor linqconnect
Thanks a lot
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
Re: Retrieving Objects from the Identity Cache
Thank you for clarification, we have reproduced the issue. We will inform you when it is fixed.
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
Re: Retrieving Objects from the Identity Cache
We have fixed the problem with getting entities directly from the cache for commands like
'context.Depts.First(d => d.Deptno == literal)'.
Also, we have implemented getting entities by keys of type Int16.
These changes will be available in the nearest build. We will post here when this build is released.
'context.Depts.First(d => d.Deptno == literal)'.
Also, we have implemented getting entities by keys of type Int16.
These changes will be available in the nearest build. We will post here when this build is released.
Re: Retrieving Objects from the Identity Cache
New build of LinqConnect 4.1.82 is available for download now!
It can be downloaded from http://www.devart.com/linqconnect/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=31&t=24844
It can be downloaded from http://www.devart.com/linqconnect/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=31&t=24844