VS C# Entity Framework 寫API 的一些方法註記
要將兩張表合併的方式
在SQL上面的用法是
select *
from [dbo].[TB_AREA] as a join [dbo].[TB_CITY] as c on a.CityID = c.id
意思是 把TB_AREA表單 加入 TB_CITY 表單,做成 c表單,然後兩個表單的關聯是TB_AREA的CityID =TB_CITY的id
如我們要使用VS C# Entity Framework的話要使用如下的方程式
dbo.TB_TRAVELESSENTIALSDETAIL
.Join(dbo.TB_TRAVELESSENTIALS, ted => ted.TravelEssentialsID, te =>te.Id,(ted,te) =>new { ted,te})
然後要取得時間的寫法是
((DateTime)s.ted.TravelEssentialsDetailCreateTime).ToString("yyyy/MM/dd")
下方為一小段範例程式碼
var TEList = dbo.TB_TRAVELESSENTIALSDETAIL
.Join(dbo.TB_TRAVELESSENTIALS, ted => ted.TravelEssentialsID, te =>te.Id,(ted,te) =>new { ted,te})
.Where(w => w.ted.Del == "N").ToList().Select(s => new TEList
{
TEID = s.ted.Id,
TECategoryName = s.te.TravelEssentialsName,
TEName = s.ted.TravelEssentialsDetailContent,
TECreateDate = ((DateTime)s.ted.TravelEssentialsDetailCreateTime).ToString("yyyy/MM/dd"),
TEUrl = s.ted.TravelEssentialsDetailUrl,
}).ToList();
result.ErrCode = 0;
result.TE = TEList;
留言
張貼留言