如何使用linq命令选择此数据

时间:2016-06-13 12:57:11

标签: mysql linq visual-studio select join

我有一个名为attraction的表,它有一个id列,它是表type的{​​{1}}的复合键。

  

吸引力:id,name,city

     

价格:id,类型,价格

如何在Visual Studio中按price在一行中选择这样的数据:

linQ

1 个答案:

答案 0 :(得分:0)

You want to access anonymous type to some kind of object and to acheive this you can try like 
declare array of 
var data= new[] { new 
            { 
                Id= 0,
                Name = "",
                City = "",
                Price1 = 0,
                Price2 = 0,
            } }.ToList();

then you can write query like

data = (from a in attraction 
        join p in price on a.Id equals p.Id
        select new
        {
                Id= a.Id,
                Name = a.Name,
                City = a.City,
                Price1 = a.Price,
                Price2 = p.Price,
        }).ToList(); 

Try above