2014-11-05 28 views
0

我想操縱從我的數據庫中的數據轉換它列出前一個長長的清單選擇將其綁定前處理數據
我有下面的代碼從我的數據庫獲取所需的數據結合C#的Windows Phone

var tdr = 
    from p in ctx.Transactions 
    join c in ctx.Type on p.Type equals c.Id 
    where p.Date > DateTime.Today.AddDays(-1 * ra) && c.Type1.Equals(ty) 
    orderby p.Date descending 
    select new { Id = p.Id 
      , amont = p.Amont 
      , type = p.Type 
      , des = p.Des 
      , dated =p.Date 
      , Aid=p.Acc 
      }; 

我想使用的功能結合之前改變一些值它

list32.ItemsSource = tdr.ToList(); 

我試圖改變查詢這樣的事情,但它沒有工作

select new { Id = p.Id 
      , amont = p.Amont 
      , type = p.Type 
      , des = p.Des 
      , ***dated =somefunction(p.Date)*** 
      , Aid=p.Acc }; 

任何幫助表示讚賞
感謝

+0

到底是什麼問題?什麼是錯誤信息?什麼是數據源(ctx.Transactions) - 對象集合,EF DataSet ...? – 2014-11-05 09:14:03

+0

在System.Data.Linq.ni.dll中發生類型'System.NotSupportedException'的異常,但未在用戶代碼中處理 附加信息:方法'System.String ToString(System.String)'不支持轉換爲SQL。 – Raminhz 2014-11-05 09:33:31

回答

0

應該有做你想要的東西沒有問題。
下面是一個例子:

void Main() 
{ 
    var i = Enumerable.Range(3,4); 


    i.Select (x => new { sq = x*x 
         , cu = MyMethod(x) 
         }    
      ); 
} 

// Define other methods and classes here 
public int MyMethod(int anInt){ 
    return anInt*anInt*anInt; 
} 

這將導致:

sq  cu 
--------- 
9  27 
16  64 
25  125 
36  216 
86  432 
+0

很高興知道它應該工作,但它不是 - 但這是錯誤 - 在System.Data.Linq.ni.dll中發生類型'System.NotSupportedException'的異常,但未在用戶代碼中處理 其他信息:方法'System.String ToString(System.String)'沒有支持到SQL的轉換。 – Raminhz 2014-11-05 09:33:16

+0

謝謝,我知道它應該工作,我讀了錯誤,並得到它 - 謝謝 – Raminhz 2014-11-05 09:36:55

+0

很高興我能幫助:) – Noctis 2014-11-05 09:51:40