Selection from several tables

1

I have this query that works well

 var rest = (from de in se.DeliveryConfiguration 
             join re in se.restaurant on de.Restaurantid equals re.RestaurantID 
             where (de.Position.Distance(geografi)/1000) < de.Distance 
             select re).ToList();

Now I need to add the table priceitem and this get MIN(price) where Price <> 0 and of course following the relationship of the id

Here the tables

    
asked by Efrain Mejias C 27.09.2016 в 20:04
source

2 answers

2

If you are working with the entity framework, you should be able to obtain the objects of the consult or set them to the main object, which is what I see is, after this send a saveOrUpdate, through the entity framework, so you avoid being Separate queries, just by consulting, you should see in the object the relationships it maintains, that is the advantage of working with an ORM.

    
answered by 28.09.2016 / 00:52
source
1

You can add more than one join and a group by which in the case of several columns you group them together {pr.Col1, pr.Col2} this group has a Key property, which is of the anonym type that you create in the group by or if it is a single column will be this same type, this group is a list of elements so you can indicate min, max, sum and others

var rest = (from de in se.DeliveryConfiguration 
         join re in se.restaurant on de.Restaurantid equals re.RestaurantID 
         join pr in priceitem on  re.ItemID equals pr.itemid
         where (de.Position.Distance(geografi)/1000) < de.Distance &&
                pr.price !=0
         group pr by p.itemid into prGrupo     
         select new {re, minPrice = prGrupo.Min(t=> t.price)    ).ToList();
    
answered by 28.09.2016 в 00:38