Hi,
i have the following case:
I have an object A witch references object B. So, A has a foreign key to B. I would like to preload all A objects in Cache and then execute a query to get a subtotal of A's referencing a particular B. Please confirm me if the following method i use is the recomended one.
I have preloaded all A objects in the Cashe by executing:
1) DomainModelEntityManager.DefaultManager.A.Execute();
I would like to query the cashe and get only some A objects that reference a specific B object.
So i write something like this:
2) DomainModelEntityManager.DefaultManager.A.Where(A.B.Id = MyId).With(QueryStrategy.CacheOnly).Execute();
This will return nothing as, if i understand correctly, it will search in Cashe for objects B with the specific Id but, since no object B's are loaded, it will fail.
if i rewrite 1) as:
1a) DomainModelEntityManager.DefaultManager.A.Include("B").Execute();
Everything works fine.
If i rewrite 2) as:
2a) DomainModelEntityManager.DefaultManager.A.Where(A.B_fk_Id= MyId).With(QueryStrategy.CacheOnly).Execute();
Everything works again fine. This time i use the genrated by the object mapper foreign key property in my query predicate and if i understand correctly no access to B property was required to test for B.Id == MyId equality.
So here are the possible combinations that work for me.
A) Preload B objects with A's
1a) DomainModelEntityManager.DefaultManager.A.Include("B").Execute();
2) DomainModelEntityManager.DefaultManager.A.Where(A.B.Id = MyId).With(QueryStrategy.CacheOnly).Execute();
B) Use the genrated by the object mapper foreign key property and and not have to preload B's.
1) DomainModelEntityManager.DefaultManager.A.Execute();
2a) DomainModelEntityManager.DefaultManager.A.Where(A.B_fk_Id= MyId).With(QueryStrategy.CacheOnly).Execute();
Finally i would like to ask why when i use the floowing method:
2b) DomainModelEntityManager.DefaultManager.A.Where(A.B_fk_Id= MyId).With(QueryStrategy.Normal).Execute();
i get this exception:
Something in this query is not supported by the Microsoft Entity Framework. Perhaps the query compares entities or non-primitive types. For example, “Where(o => o == anOrder)” compares Order entities. Instead, please try “Where(o => o.Id == anOrder.Id)” which compares integer Id values.
I get this exception whenever i try to put in a Where clause a predicate containing a foreign key property and executing the query on the datasource.
Thanks in advance,
Kostas