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

标签 mysql linq visual-studio select join

我有一个名为attraction的表,它有一个id列,它是一个带有表price的type的复合键.

Attraction: id, name, city

price: id, type, price

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

id, name, city, type1_price, type2_price

最佳答案

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 

关于mysql - 如何使用linq命令选择此数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37790459/

相关文章:

mysqlbackup : ERROR: Opening of file/var/lib/mysql/ibdata1 failed. 错误代码 : 13, 权限被拒绝

python - 使用python代码将MySql列中的 "NAN"值转换为NULL

c# - Linq.Where(x=>x==1) - 编译器在做什么

c# - 使用 LINQ 将数据从一个列表复制到另一个列表

c# - 如何在 Visual Studio 2008 中为简单的 Windows 窗体应用程序插入下拉菜单?

php - mySQL 数据库未从表单更新

python - 使用 python 将值插入表中

c# - 转换 DateTime 时不支持系统 - DotNetHighChart

C#如何通过标签数组在字典键中搜索

c++ - 如何在 CMake 项目中包含 IntelliSense 的外部库源?