Page 1 of 1

strange problem using dotconnect

Posted: Wed 30 Nov 2011 10:21
by shaharw18
hi,

here's a description of the code with the problem:

DB.MainDataContext context = new DB.MainDataContext();
var sections = from s in context.Sections orderby s.Title select s;

foreach(var section in sections){
*var place = from p in context.Places where p.SectionId == section.Id orderby p.Title select p;

if ( *place. ?

first potential problem/question (*) can I use "var" inside a foreach loop?
isn't it a problem?

* the main problem: when typing "place." (which is the linq object) the intellisense does'nt display all the property fields existing in "place".
it was supposed to popup. so I understand that something with the declarations I've made is wrong, because visual studio doesn't recognize "place".

does anyone got a clue ?

thanks in advanced.

Shahar Weinstein.

Posted: Thu 01 Dec 2011 15:37
by StanislavK
You should be able to use the 'var' keyword inside loops. The 'var' keyword only means that you leave determining the exact type of the variable for the compiler.

As for the 'place' properties, the problem is that the variable you've declared is of type 'IQueryable', not 'Place' itself. I.e., it is a collection and thus the members Intellisense show you are properties and methods of the collection type. To work with the object of the Place type, you should enumerate the collection. E.g., you can use

Code: Select all

var firstPlace = place.FirstOrDefault();
Please tell us if this helps.

Posted: Fri 02 Dec 2011 08:32
by shaharw18
thanks alot that was the issue,
and I solved it by using Single method to query one row only.


Shahar.