SQL:Linq union的用法?
SELECT date,total_usage_T1 as TotalUsageValue,'T1' as UsageType FROM TblSayacOkumalari
UNION ALL
SELECT date,total_usage_T2 as TotalUsageValue,'T2' as UsageType FROM TblSayacOkumalari
我嘗試做將其轉換爲LINQ
IEnumerable<TblSayacOkumalari> sayac_okumalari = entity.TblSayacOkumalari
.Select(x => new
{ x.date, x.total_usage_T1 })
.Union(entity.TblSayacOkumalari.Select(x => new
{ x.date, x.total_usage_T2 }));
但我不知道如何'T1' as UsageType
轉換爲LINQ。另外我的工會使用也是不正確的。
這樣我的表中的字段:
| date | total_usage_T1 | total_usage_T2 |
| 2010 | 30 | 40 |
| 2011 | 40 | 45 |
| 2012 | 35 | 50 |
我想這樣
| date | TotalUsageValue | UsageType |
| 2010 | 30 | T1 |
| 2011 | 40 | T1 |
| 2012 | 35 | T1 |
| 2010 | 40 | T2 |
| 2011 | 45 | T2 |
| 2012 | 50 | T2 |
我很努力,但不能。請幫忙。
好的。但如何將''T1'作爲UsageType'轉換爲linq查詢 – 2012-07-11 06:19:19
@AliRızaAdıyahşi - 檢查我編輯的答案.... – 2012-07-11 06:22:21
'unioun = union'和'concat = union all'是嗎? – 2012-07-11 06:33:44