Say, I have the following tables in SQLCe Database:
Table Country Table Cities
----------- -------------
Pkey countryname Pkey Fkey cityname
1. USA 1. 1. LA
2. Canada 2. 2. Toronto
3. 1. NYC
4. 1. Chicago
Here the code to get the cities:
public IList GetCities(){
IList cityList = null;
using (CountryDataContext context = new CountryDataContext(ConnectionString))
{
IQueryable query = from c in context.Cities select c;
cityList = query.ToList();
}
return cityList;
}
Questions are :
-
How do I select using normal Select-statement : Select cityname where country = USA?
-
How do I select the country and get the primary key ?
Select ID, Countrynamethen, I can pass the Pkey and do a select again
Select cityname where Fkey = “1”;
would apreciate any help or sample on LinqToSQL for normal Databse operation.
Thanks
This should get you your first question:
I’m not sure I understand what you’re asking in the second question, but I think this may be it: