Below is the code where I try to do a simple Linq-to-entities framework query, and I want to also access the results one by one:
inctDomainContext innn = new inctDomainContext();
var exx = from c in innn.cordonnes select c;
foreach (var i in exx) {
//doing something here but the programe doesn't enter the loop
}
Why doesn’t the program enter into foreach loop?
it appears you’re working with WCF Ria Services in Silverlight. This is totally different from how things work when using EntityFramework directly. In your case, you have to “load” the data, before being able to access it.
To do this, you have to call the “Load” method on the domain context and pass in the query you need (in your case
GetCoordonneQuery()), and then you can pass a callback to be executed when the load asynchronous call is finished. The callback will have access to the results of the query. Here’s an example:when the
OnLoadCoordonneCompletedis called (i.e: when the asynchronous load call is finished), the context.Coordonnes will be loaded and contain the data you want.Hope this helps