所以我試圖從腳本任務中的表中獲取最近的記錄。該錯誤是在未來的LINQ查詢,它看起來像:在linq的日期時間
"Could not Translate expression 'Table(SSASLogging).Select(r=>r.TimeStamp).Max()' into SQL and could not treat it as a local expression."
問題在於DateTime數據類型,但我需要的日期時間把它給我的SSIS變量。我知道這可以在一個執行SQL任務中輕鬆完成,但是我現在太放棄了!我知道有一些用於DateTime的LinqToSQL方法,但它們用於比較它看起來像,我不知道如何在這裏應用它們。
public DateTime getLatest()
{
DateTime result = new DateTime();
//temp dummy/defaul date is two days ago
result = DateTime.Now.AddDays(-2);
try
{
//get the data connection string from the connection manager
RW = (string)Dts.Connections["ReportingWarehouse"].ConnectionString;
//Remove the Provider, Auto Translate, and Application
//as it is not a parameter for the DataContext constructor
RW = RW.Remove(RW.IndexOf("Provider=SQLNCLI10.1;"), "Provider=SQLNCLI10.1;".Length);
RW = RW.Remove(RW.IndexOf("Auto Translate=False;"), "Provider=SQLNCLI10.1;".Length);
RW = RW.Remove(RW.IndexOf("Application"),RW.Length - RW.IndexOf("Application"));
MessageBox.Show(RW);
//get the last insertion date from the SSASLoging table
using (DataContext RWData = new DataContext(RW))
{
Table<SSASLogging> records = RWData.GetTable<SSASLogging>();
var rs = (from r in records
select r.TimeStamp).Max();
//result = rs.FirstOrDefault();
}
}
catch (Exception e)
{
MessageBox.Show("Exception in Retrieving latesttime" + e.Message + "/n"
+ e.StackTrace);
}
return result;
}
}//end partial class
[Table]
public class SSASLogging
{
[Column(Name = "CREATED_TIMESTAMP")]
private DateTime timeStamp;
public DateTime TimeStamp
{
get { return this.TimeStamp; }
}
}//End SSASLogging
數據庫和模型中的'r.TimeStamp'類型是什麼? – MarcinJuraszek 2013-03-15 07:07:07
數據庫中的類型爲DateTime,包中的類型爲DateTime。我不確定你的模型是什麼意思? – 2013-03-15 07:13:32
您是否可以從'r.TimeStamp'中選擇所有日期的列表,而不指定'Max()'? – MarcinJuraszek 2013-03-15 07:17:24