strange problem using dotconnect

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for SQLite
Post Reply
shaharw18
Posts: 43
Joined: Thu 20 Oct 2011 20:07

strange problem using dotconnect

Post by shaharw18 » Wed 30 Nov 2011 10:21

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.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Thu 01 Dec 2011 15:37

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.

shaharw18
Posts: 43
Joined: Thu 20 Oct 2011 20:07

Post by shaharw18 » Fri 02 Dec 2011 08:32

thanks alot that was the issue,
and I solved it by using Single method to query one row only.


Shahar.

Post Reply