EF Lambda 多表查询
2015-08-28 17:40
344 查看
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();
}
}
}
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();
}
}
}
相关文章推荐
- HDU 1286 找新朋友(欧拉函数)
- adb 连不上设备的种种情况
- Impdp ORA-39083、ORA-01403报错问题分析解决
- App Indexing
- JME3资源管理之二:AssetLoader和AssetLocator
- 通过Java字节码发现有趣的内幕之String篇(一)
- Set类、Collections
- spring security配置的注意细节
- 程序员如何高效阅读
- iOS设计模式--迭代器模式
- png压缩
- mongodb中distinct查询
- 集合-List实现类、泛型
- CentOS、Ubuntu、Debian三个linux比较异同
- gsensor架构和原理分析
- ActionBar的完整介绍
- 深入浅出LSTM神经网络
- maven导出项目依赖的jar包
- 为CoreData封装一个简易的操作类
- ios中sqlite数据库的原生用法