How can I select data with linq to sql from another query?

How can I select data with such linq to sql code, it's something wrong, i must compare WHERE, from st1 and st2, but something wrong. Also spaller didn't light this variables in where

var st1 = (from a in db.RouteDetail
                          where a.Station == "Гродно"
                          select new 
                          {
                              a.Route,
                          });
                var st2 = (from c in db.RouteDetail
                          where c.Station == "Лида"
                          select new 
                          {
                              c.Route,
                          });
                var res = (from d in db.RouteDetail
                           where st1.Route == st2.Route
                           select d);

Help me to do this, please.

Answers


I think what you mean to do is something like this :

var st1 = (from a in db.RouteDetail
                      where a.Station == "Гродно"
                      select new 
                      {
                          a.Route,
                      });
var st2 = (from c in db.RouteDetail
                      where c.Station == "Лида"
                      select new 
                      {
                          c.Route,
                      });

Both st1 and st2 now contain IQueryable types which allow you to enumerate over them. I'm assuming that your two queries only return one result in which case:

var station1 = st1.FirstorDefault();
var station2 = st2.FirstorDefault();

var res = (from d in db.RouteDetail
           where station1.Route == station2.Route
           select d);

Will do what you need it to do (provided they return a result theres no safety here for null exceptions). If however there is more than one result, it will only return the first match. In which case you will need to work out all the possible compositions from the values in st1 and st2


Need Your Help

MonoTouch: Using ServiceStack caused JIT error?

c# monotouch monodevelop jit servicestack

I am using the MonoTouch build of Service Stack from https://github.com/ServiceStack/ServiceStack/tree/master/release/latest/MonoTouch

debugging mongodb queries and other functions in php

php debugging logging mongodb

How do you go about debugging your php mongodb code?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.