views:

47

answers:

2
A: 

I presume you have a model generated either with LINQ to SQL or Entity Framework. Also, I'm assuming foreign key relationships have been set.

var details = db
    .Cuisines
    .Where(c => c.Cuisine=="something")
    .SelectMany(c => c.RestaurantCuisines)
    .Select(rc => rc.Restaurant.RestaurantDetails)
    .Where(rd => rd.Area=="something")
;
Pablo Montilla
I am getting the result from this query :select * from restaurant_details where restaurant_id in (select restaurant_id from restaurant_cuisine where restaurant_cuisine.cuisine_id in (select id from cuisine where cuisine = 'something') and area = 'something'Now i want to convert it into Linq.
Nirmal
A: 

Done with the linq query using following lines of code :

            c = from q in dc.restaurant_cuisines
                    where q.cuisine.cuisine1.Contains(cuisine)
                        && q.restaurant.price.ToString().Length == price.Length
                    select new NearBy { NearById = q.restaurant.id, NearByLongitude = (double)q.restaurant.longitude, NearByLatitude = (double)q.restaurant.latitude };
        }
        int[] ids = new int[c.Count()];

var lon = from q1 in dc.area_maps where q1.area.ToLower() == area.ToLower() select q1.longtitude;
        var lat = from q1 in dc.area_maps where q1.area.ToLower() == area.ToLower() select q1.latitude;
        foreach(NearBy n in c)
        {
            result = calcDistNew((double)lat.FirstOrDefault(), (double)lon.FirstOrDefault(), n.NearByLatitude, n.NearByLongitude);
            ids[i++] = n.NearById;
        }


        var r = from q in dc.restaurant_details
                where 1 == 1 &&
                (ids).Contains(q.restaurant_id)
                select new Restaurant
                {
                    Restora_id = q.restaurant_id.ToString(),
                    Name = q.restaurant.name,
                    Foodtype = q.restaurant.foodtype.foodtype1,
                    Avg_rating = q.restaurant.avg_rating.ToString(),
                    Featured = q.restaurant.featured.ToString(),
                    CuisineList = getCuisine(q.restaurant_id),
                    Restora_type = q.type,
                    Distance = Math.Round(calcDistNew((double)lat.FirstOrDefault(), (double)lon.FirstOrDefault(), (double)q.restaurant.latitude, (double)q.restaurant.longitude), 2),
                    Newarrival = q.restaurant.newarrival.ToString(),
                    CountRecord = ids.Length.ToString()
                };
        var d = r.AsEnumerable().OrderBy(t => t.Distance);
        var g = d.Take(recordSize + 10).Skip(recordSize);
        return g.ToList();

Please note that above displayed code generated with some changes from the initial requirements.

Nirmal