【问题标题】:How to use linq command to select this data如何使用 linq 命令选择此数据
【发布时间】:2016-06-13 12:57:11
【问题描述】:

我有一个名为attraction 的表,它有一个id 列,它是表pricetype 的组合键。

景点:身份证、姓名、城市

价格:id、类型、价格

如何在 Visual Studio 中通过linQ 在一行中选择这样的数据:

id, name, city, type1_price, type2_price

【问题讨论】:

  • 您说的是由位于不同表中的两列组成的复合键。怎么会?或者您是说attraction 表中的id 列指的是price 表中的type 列。

标签: mysql linq visual-studio select join


【解决方案1】:
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 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-02
    • 1970-01-01
    • 2021-12-16
    • 2011-05-07
    相关资源
    最近更新 更多