zoukankan      html  css  js  c++  java
  • EF Lambda 多表查询

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;

    namespace MvcForLamadaToTableJion.Controllers
    {
    public class HomeController : Controller
    {
    public ActionResult Index()
    {
    LamadaJoinEvent();


    return View();
    }

    /// <summary>
    /// 实体类
    /// </summary>
    public class Product
    {

    public int ProductId { get; set; }

    public string ProductName { get; set; }
    }

    #region 填充 数据
    static Product[] product2 =
    {
    new Product{ProductId=1,ProductName="Apple"},
    new Product{ProductId=4,ProductName="Orange"},
    new Product{ProductId=5,ProductName="Berry"},
    };
    static Product[] product3 =
    {

    new Product{ProductId=4,ProductName="Orange"},
    new Product{ProductId=5,ProductName="Berry"},
    };
    #endregion

    #region 调用lamada多表查询方法
    /// <summary>
    /// 调用lamada多表查询方法,
    /// 说明:这种方法目前比较适合两张表连接,三张表以上估计够呛
    /// </summary>
    public void LamadaJoinEvent()
    {


    var result3 = product2.Join
    (
    product3,
    x => x.ProductId,
    c => c.ProductId,
    (x, c) => new { x.ProductId, c.ProductName }
    );

    foreach (var a in result3)
    {
    ViewBag.data +="||" +a.ProductName;
    }


    }
    #endregion

    public ActionResult About()
    {
    ViewBag.Message = "你的应用程序说明页。";

    return View();
    }

    public ActionResult Contact()
    {
    ViewBag.Message = "你的联系方式页。";

    return View();
    }

    }
    }

  • 相关阅读:
    【CSS】盒子模型的计算
    【CSS】定义元素的位置
    【Jenkins】安装插件
    安装【Jenkins】
    Python【unittest】模块
    Python【pyyaml】模块
    CentOS下安装gcc和gdb
    汇编学习笔记(15)综合研究
    汇编学习笔记(14)BIOS对键盘输入的处理
    汇编学习笔记(13)直接定址表
  • 原文地址:https://www.cnblogs.com/linbin524/p/4767126.html
Copyright © 2011-2022 走看看