我有一個使用Service Broker的隊列中獲得所需要的一些處理通知的Windows服務:服務代理與實體框架6
var cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["MathsEngine.Properties.Settings.TargetConnectionString"].ToString());
var cmd = new SqlCommand("WAITFOR (RECEIVE * FROM dbo.MathsEngineQueue);", cnn) {CommandTimeout = 0};
cnn.Open();
// Execute the command - we will wait here until a new entry appears in the Notification Queue
//
SqlDataReader reader = cmd.ExecuteReader();
// Get the message text from the reader
//
while (reader.Read())
{
// Get the message body text and convert into a legible format
//
_messageText = Encoding.Unicode.GetString(reader.GetSqlBinary(reader.GetOrdinal("message_body")).Value);
}
reader.Close();
reader.Dispose();
cmd.Dispose();
我現在開始使用實體框架6.0做我所有的數據庫交互。我一直在試圖找到一種方法來監視隊列並通過EF獲取任何消息。到目前爲止,我發現的唯一部分答案涉及非常複雜的SQLDependency使用,它仍然不讓我將消息從隊列中取出。
在EF中是否有這樣做的方法,或者我現在堅持這個區域不變嗎?